2013-10-21 40 views
1

我對文件進行了一些更改並提交它們。然後我結帳到一個較舊的分支。Git:爲什麼結賬到舊分支後,新的提交消失了?

之後,我發現我所做的所有更改都消失了,我所做的提交也消失了。

我如何找到我所做的所有更改?


編輯

這是從我的終端歷史複製:

$ git commit -m 'done clean FNAG Yishu' 
[detached HEAD 8a67a04] done clean FNAG Yishu 
3 files changed, 1121 insertions(+) 
create mode 100644 data/data_afterClean/amazon_Revised.txt 
create mode 100644 data/data_afterClean/epinions_Revised.txt 
create mode 100644 data/data_afterClean/slideshare_Revised.txt 

但是,當我嘗試push錯誤發生:

$ git push 
warning: push.default is unset; its implicit value is changing in 
Git 2.0 from 'matching' to 'simple'. To squelch this message 
and maintain the current behavior after the default changes, use: 

    git config --global push.default matching 

To squelch this message and adopt the new behavior now, use: 

    git config --global push.default simple 

See 'git help config' and search for 'push.default' for further information. 
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 
'current' instead of 'simple' if you sometimes use older versions of Git) 

To https://github.com/xxx/xxx.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to 'https://github.com/xxx/xxx.git' 
hint: Updates were rejected because a pushed branch tip is behind its remote 
hint: counterpart. If you did not intend to push that branch, you may want to 
hint: specify branches to push or set the 'push.default' configuration variable 
hint: to 'simple', 'current' or 'upstream' to push only the current branch. 
+1

等一下。是什麼讓你認爲這個提交消失了? –

+0

你確定你在你認爲你做的那個分支上做了那個提交嗎? – Shahbaz

+0

如果您沒有將分支與較新的更改合併到較舊的分支,它們將不可見,除非您切換回分支並使用較新的更改... – akluth

回答

3

你已經承諾一個分離的頭,而不是分支。您可以通過使用我們回到提交的SHA-1,在git commit輸出中列出:

git checkout 8a67a04 

如果你想保持這個承諾的一個分支,結賬後創建:

git checkout -b <branchname> 
1

提交將被記錄爲當你的時候,你所處的分支的新尖端承諾,所以你可以通過簽出該分支來切換回去。

日誌總是顯示您當前所在分支的歷史記錄;當檢出開關分支時,您不再位於您進行提交的分支上,因此不再顯示。

+0

如果該分支沒有名稱,我該怎麼辦?我只是從服務器上取下一些新東西,改變它們並提交。 –

+0

在這種情況下,沒有分支指向提交,所以它在下一個'git gc'上被丟棄。 * reflog *可能仍然有一個指針,'git fsck'會報告一個未連接的提交對象。請注意,沒有連接的提交是正常的,這些都是從rebase剩下的。 –

相關問題