2011-01-20 66 views
3

以下是我執行的一些git動作。正如你所看到的,我做了一個新的分支,修改了我的文件,然後提交了更改。在換回另一個分支後,希望合併後,我剛剛開始工作的分支消失了。git中的神祕消失分支

有誰知道我可以從fixed_merge_branch恢復文件嗎?我嚇壞了!

[email protected]$ git branch fixed_merge_conflict 
[email protected]$ git checkout fixed_merge_conflict 
M ArtworkViewController.h 
M ArtworkViewController.m 
M ArtworkViewController.xib 
M Classes/DFRAppDelegate.h 
M Classes/DFRAppDelegate.m 
M Classes/WorkGalleryViewController.m 
M Classes/WorkGalleryViewController.xib 
M DFR.xcodeproj/project.pbxproj 
M DFRViewController.xib 
M Data.h 
M Data.m 
M MainWindow.xib 
M cn.lproj/Localizable.strings 
M en.lproj/Localizable.strings 
A fr.lproj/Localizable.strings 
Switched to branch 'fixed_merge_conflict' 
[email protected]$ git add . 
[email protected]$ cd Classes/ 
[email protected]$ git add . 
[email protected]$ cd .. 
[email protected]$ git add -u 
[email protected]$ git status 
# Not currently on any branch. 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# modified: ArtworkViewController.h 
# modified: ArtworkViewController.m 
# modified: ArtworkViewController.xib 
# modified: Classes/DFRAppDelegate.h 
# modified: Classes/DFRAppDelegate.m 
# modified: Classes/WorkGalleryViewController.m 
# modified: DFR.xcodeproj/project.pbxproj 
# modified: Data.h 
# modified: Data.m 
# modified: MainWindow.xib 
# modified: cn.lproj/Localizable.strings 
# modified: en.lproj/Localizable.strings 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# fr.lproj/ 
[email protected]$ git commit -m "re-did changes lost by merge screw up" 
[detached HEAD 858491f] re-did changes lost by merge screw up 
12 files changed, 110 insertions(+), 50 deletions(-) 
[email protected]$ git checkout develop 
Previous HEAD position was 858491f... re-did changes lost by merge screw up 
Switched to branch 'develop' 
[email protected]$ git branch 
    artwork_model 
    artwork_model_localisation 
    artwork_screen 
* develop 
    logger 
    master 
    start_artwork_model 
[email protected]$ git merge fixed_merge_conflict 
fatal: 'fixed_merge_conflict' does not point to a commit 
[email protected]$ git checkout fixed_merge_conflict 
error: pathspec 'fixed_merge_conflict' did not match any file(s) known to git. 
[email protected]$ git checkout fixed_merge_conflict 
error: pathspec 'fixed_merge_conflict' did not match any file(s) known to git. 
[email protected]$ git branch 
    artwork_model 
    artwork_model_localisation 
    artwork_screen 
* develop 
    logger 
    master 
    start_artwork_model 
[email protected]$ git checkout 
[email protected]$ git branch 
    artwork_model 
    artwork_model_localisation 
    artwork_screen 
* develop 
    logger 
    master 
    start_artwork_model 
[email protected]$ pwd 
/Users/tristan/Documents/DFR 
[email protected]$ 

非常感謝!

回答

8

那麼我不完全明白爲什麼分支'消失',但不用擔心,你的文件沒有。

您可以通過多種方式找到他們:

  • 當你離開你的匿名分支您可以使用由git checkout打印的消息:「上一個頭的位置是858491f」。
  • 您可以使用git reflog並找到文件的提交。

然後你就可以運行這個重新創建分支:

git checkout 858491f -b fixed_merge_conflict 

,然後你可以做您的合併:

git checkout develop 
git merge fixed_merge_conflict 

或者你也可以一步完成合並,如果你不不關心分支:

git merge 858491f 
+0

非常感謝!那正是我需要的。 – WoodenKitty 2011-01-20 05:58:18

0

由於某種原因,你越來越一個detach head situation。我不完全確定這是如何導致在一個常規的git回購,但我遇到它使用git svnand came up with my own solution here)。在創建新分支時,可能並不是上游回購。通常當你得到一個detached head,當你做一個git branch,你會看到(asterisk) (no branch)(不知道如何做一個字面星號降價)