2017-09-06 179 views
-1

我正在研究一個項目,在我的代碼中進行了一些更改(在Itellij IDE中),並且由於我在終端中執行了兩步以下的操作,而且我看到一些更改進入了主存儲庫(不是我的更改或我之前工作的任何內容)。 有誰知道它爲什麼這麼做?當用戶在「git add」和「git commit」之前做「git push」會發生什麼?

注意: 推送的更改不是我的代碼。從我的終端

  • 添加

    1. 混帳拉(全高達至今,我收到)從我的終端
    2. 混帳推(而不是 「git的add」 和 「git的承諾」)附加信息(編輯) 是的,我在做一個git push之前在本地存儲庫中進行了一些更改。但是當我做了「git push」的錯誤時,我的本地承諾的更改沒有被推送,而是其他人的代碼被推到了我所拉的地方。

我不明白爲什麼GIT中這樣做,並問一個問題在這裏認識的思想。

該問題被要求知道可能的原因而不影響我對答案的看法。

+2

你的問題最好含糊不清。如果你沒有做一個本地提交,push什麼也不做。 –

+0

@AbhijitSarkar這也是我的一般感受。我嘗試了一個答案,試圖解釋如果一個推動實際上通過了可能發生的事情。 –

+0

也許你的IDE自動提交你的代碼。使用'git log'或'git reflog'來找出發生的事情。 – haolee

回答

0

很難準確地說出發生了什麼事情,因爲您沒有告訴我們您在當時執行了意外的git pull後跟git push的當地分支的狀態。假設你沒有在遠程跟蹤分支上沒有出現的本地提交,那麼我預計git push會失敗,說明遠程已經是最新的。如果在偶然的git pull之前運行git status,並且Git告訴你你的分支爲0,它會提前到達遠程。

第二步,你做了一個git push。假設這已經過去了,那麼我會解釋它意味着你實際上有一些本地提交還沒有被推送。所以,發生的一切就是你之前的一些本地工作被推到了倉庫,可能過早。假設這些提交是真誠的,你可能沒有什麼可擔心的。如果不是,那麼您可以使用git revert來恢復其中的一個或多個提交。

0

這是當我試圖複製

[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 

現在推的是成功的。

就你而言,當你應用推送時,肯定有一些本地提交的更改。

相關問題