当用户在“git add”和“git commit”之前执行“git push”时会发生什么?

时间:2017-09-06 01:43:24

标签: git git-commit git-push git-pull git-add

我正在研究一个项目,在我的代码中进行了一些更改(在Itellij IDE中),我错误地在终端中执行了两个步骤,我看到主存储库中有一些更改(不是我的更改或我曾经工作的任何内容)先前)。 有谁知道为什么会这样做?

注意: 推送的更改不是我的代码。

    从我的终端
  1. git pull(我收到了所有最新消息)
  2. 从我的终端
  3. git push(而不是“git add”和“git commit”)

    • 添加其他信息(已修改) 是的,在我进行git推送之前,我在本地存储库中进行了一些更改。但是,当我犯了“git push”的错误时,没有任何我本地提交的更改被推送,而是其他人的代码被推了,我已经拉了。
  4. 我无法理解为什么git这样做,并想在这里提出一个问题来理解。

    这个问题被要求知道可能的原因,而不影响我对答案的看法。

2 个答案:

答案 0 :(得分:0)

很难准确说出发生了什么,因为您在意外git pull后跟git push时没有告诉我们您当地分行的状态。假设您没有在远程跟踪分支上显示的本地提交开始,那么我原本期望git push失败,说远程已经是最新的。如果您在意外git status之前运行git pull,那么这个标志就是这样,而且Git告诉您,你的分支在遥控器前提交了0次。

第二步,你做了git push。假设这个经历了,那么我会把它解释为意味着你确实有一些本地提交尚未被推送。所以,所发生的一切都是你以前的一些本地工作被推到存储库,可能是过早的。假设这些提交是真诚的,你可能没有什么可担心的。如果没有,那么您可以使用git revert始终还原一个或多个提交。

答案 1 :(得分:0)

当我尝试复制

时会发生这种情况
user@machine MINGW64 /c (11.1.0)
$ git pull
Already up-to-date.

Git pull是成功的,我对我的文件进行了更改。

user@machine MINGW64 /c (11.1.0)
$ git push
Everything up-to-date

没有发现任何东西。

user@machine MINGW64 /c (11.1.0)
$ git status
On branch 11.1.0
Your branch is up-to-date with 'origin/11.1.0'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   ReleaseNotes/Release_Notes_11.1.0.docx

no changes added to commit (use "git add" and/or "git commit -a")

当我执行git状态时,它已识别出更改

user@machine MINGW64 /c (11.1.0)
$ git add .

添加了提交文件。

user@machine MINGW64 /c (11.1.0)
$ git push
Everything up-to-date

再没有发现任何内容

user@machine MINGW64 /c (11.1.0)
$ git status
On branch 11.1.0
Your branch is up-to-date with 'origin/11.1.0'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   ReleaseNotes/Release_Notes_11.1.0.docx

状态已确定更改

user@machine MINGW64 /c (11.1.0)
$ git commit -m 'Release notes amended'
[11.1.0 28697fa] Release notes amended
 1 file changed, 0 insertions(+), 0 deletions(-)
 rewrite ReleaseNotes/Release_Notes_11.1.0.docx (62%)

本地提交

user@machine MINGW64 /c (11.1.0)
$ git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 50.57 KiB | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
remote:
remote: Create pull request for 11.1.0:
remote:   https://bitbucket.org/URL
remote:
To bitbucket.org:Project/repo.git
   7db5eb6..28697fa  11.1.0 -> 11.1.0

现在推动是成功的。

在您的情况下,应用推送时必定会有一些本地提交的更改。

相关问题