当用户在“git add”和“git commit”之前做“git push”会发生什么?
我正在研究一个项目,在我的代码中进行了一些更改(在Itellij IDE中),并且由于我在终端中执行了两步以下的操作,而且我看到一些更改进入了主存储库(不是我的更改或我之前工作的任何内容)。 有谁知道它为什么这么做?当用户在“git add”和“git commit”之前做“git push”会发生什么?
注意: 推送的更改不是我的代码。从我的终端
- 添加
- 混帐拉(全高达至今,我收到)从我的终端
混帐推(而不是 “git的add” 和 “git的承诺”)附加信息(编辑) 是的,我在做一个git push之前在本地存储库中进行了一些更改。但是当我做了“git push”的错误时,我的本地承诺的更改没有被推送,而是其他人的代码被推到了我所拉的地方。
我不明白为什么GIT中这样做,并问一个问题在这里认识的思想。
该问题被要求知道可能的原因而不影响我对答案的看法。
很难准确地说出发生了什么事情,因为您没有告诉我们您在当时执行了意外的git pull
后跟git push
的当地分支的状态。假设你没有在远程跟踪分支上没有出现的本地提交,那么我预计git push
会失败,说明远程已经是最新的。如果在偶然的git pull
之前运行git status
,并且Git告诉你你的分支为0,它会提前到达远程。
第二步,你做了一个git push
。假设这已经过去了,那么我会解释它意味着你实际上有一些本地提交还没有被推送。所以,发生的一切就是你之前的一些本地工作被推到了仓库,可能过早。假设这些提交是真诚的,你可能没有什么可担心的。如果不是,那么您可以使用git revert
来恢复其中的一个或多个提交。
这是当我试图复制
[email protected] MINGW64 /c (11.1.0)
$ git pull
Already up-to-date.
混帐拉是成功的,我做了一个改变我的文件会发生什么。
[email protected] MINGW64 /c (11.1.0)
$ git push
Everything up-to-date
什么都没有发现。
[email protected] 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")
当我这样做,它已查明变化
[email protected] MINGW64 /c (11.1.0)
$ git add .
增加了对提交文件git的状态。
[email protected] MINGW64 /c (11.1.0)
$ git push
Everything up-to-date
,没有什么是看准
[email protected] 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
状态已经确定了变化
[email protected] 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%)
本地提交
[email protected] 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
现在推的是成功的。
就你而言,当你应用推送时,肯定有一些本地提交的更改。
你的问题最好含糊不清。如果你没有做一个本地提交,push什么也不做。 –
@AbhijitSarkar这也是我的一般感受。我尝试了一个答案,试图解释如果一个推动实际上通过了可能发生的事情。 –
也许你的IDE自动提交你的代码。使用'git log'或'git reflog'来找出发生的事情。 – haolee