2017-05-14 59 views
1

我試圖從我的Git工作區推到Github,但我添加和提交的更改似乎沒有上傳。似乎在「(無分支)」,然後失去了我的變化

然後,做一個「混帳分支」我得到的東西是這樣的:

git branch 
* (no branch) 
    master 

愚蠢,我以爲我可以重新進入主與

git checkout master 

,現在我的改變似乎去了。我的主分支大約三天。似乎沒有辦法切換回這個(沒有分支)。

我檢查了這個問題Git : seemed to be in 「(no branch)」 and then lost my changes答案建議做一個git reflog show然後結帳。我想,我得到這個:

$ git reflog 
    0f27ae7 [email protected]{1}: checkout: moving from HEAD to master 
    7b8ee7b [email protected]{2}: commit: 14/05/2017 3:33pm 
    ff60409 [email protected]{3}: commit: 14/05/2017 3:33pm 
    0f27ae7 [email protected]{4}: checkout: moving from master to 0f27ae7236aabbe8cccfba82e201e36368a05054 
    0f27ae7 [email protected]{5}: commit: 11/05/2017 2:33pm 
    3e4c616 [email protected]{6}: merge origin/master: Fast-forward 
    1e79818 [email protected]{7}: commit: 10/5//2017 UI 

我試着做一結帳從0f27ae7236aabbe8cccfba82e201e36368a05054但我的變化是不回來了。我想要的是恢復我在(無分支)(承諾:14/05/2017 3:33 pm)作出的最後提交。

這裏是git branch -a結果:

$ git branch -a 
* (HEAD detached from 0f27ae7) 
    UI_linking 
    master 
    remotes/ado/newBranch 
    remotes/origin/UI_linking 
    remotes/origin/frogs1 
    remotes/origin/master 
    remotes/origin/newBranch 
    remotes/origin/newMas 

是我的變化失去了什麼?還是有辦法恢復它們?

+0

你可以顯示git branch -a嗎? – DreamInBox

+0

我將它添加到問題中。 –

回答

0

您可以恢復您的狀態git checkout 7b8ee7b其中7b8ee7b是在您的reflog中的[email protected]{2}下的哈希值 - 您在切換到主站之前的哈希值。

發生了什麼:由於某種原因,您從主分支切換到0f27ae7236aabbe8cccfba82e201e36368a05054,並以「分離頭部」狀態結束。你做了一些提交,但那些不在任何分支上。這些提交仍然存在,您可以在reflog中看到它們。

雖然0f27ae7236aabbe8cccfba82e201e36368a05054是您的主人指出的,但當您切換到散列時,您不會切換到指向該提交的任何分支。

0

從輸出git reflog我會說你的變化是在承諾7b8ee7b[email protected]{2})。

以下命令:

git branch lost 7b8ee7b 
git checkout lost 

應建立在上述一個新的分支(名爲lost)提交,然後檢查出來。

然後,你可以這樣做:

git rebase master 
git checkout master 
git merge --ff lost 

移動你恢復的master部門高層的兩次提交,並使其顯示爲master分支歷史的一部分。

如果一切都看起來不錯,那麼你可以運行git branch -d lost刪除lost分支。

0

原因是:你推動你的分支沒有宣佈一些警告,但你忽略了他們的分支。現在,這段代碼被分離到HEAD。所以你的新修改代碼將在HEAD〜上。您可以在重新記錄看到:

0f27ae7 HEAD @ {4}:結帳:從主移動到0f27ae7236aabbe8cccfba82e201e36368a05054

的方式把它找回來:

  1. 你獲取了你的混帳來源:

git fetch來源

  • 結帳爲HEAD
  • git的結帳遙控器/來源/主

  • 最後,合併0f27ae7 HEAD @ {1} to master
  • git merge HEAD @ {1}

    現在,你已經掌握了你的代碼。

    Regards,

    相關問題