神秘的Git分支消失

7
这里是我执行的一些git操作。如您所见,我创建了一个新的分支,修改了我的文件,然后提交了更改。在切换回另一个分支后,希望进行合并,我刚刚工作的分支消失了。
有人知道我如何从fixed_merge_branch中恢复文件吗?我很紧张!
1.9.2@whisperme$ git branch fixed_merge_conflict
1.9.2@whisperme$ 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'
1.9.2@whisperme$ git add .
1.9.2@whisperme$ cd Classes/
1.9.2@whisperme$ git add .
1.9.2@whisperme$ cd ..
1.9.2@whisperme$ git add -u
1.9.2@whisperme$ 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/
1.9.2@whisperme$ 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(-)
1.9.2@whisperme$ git checkout develop
Previous HEAD position was 858491f... re-did changes lost by merge screw up
Switched to branch 'develop'
1.9.2@whisperme$ git branch
  artwork_model
  artwork_model_localisation
  artwork_screen
* develop
  logger
  master
  start_artwork_model
1.9.2@whisperme$ git merge fixed_merge_conflict
fatal: 'fixed_merge_conflict' does not point to a commit
1.9.2@whisperme$ git checkout fixed_merge_conflict
error: pathspec 'fixed_merge_conflict' did not match any file(s) known to git.
1.9.2@whisperme$ git checkout fixed_merge_conflict
error: pathspec 'fixed_merge_conflict' did not match any file(s) known to git.
1.9.2@whisperme$ git branch
  artwork_model
  artwork_model_localisation
  artwork_screen
* develop
  logger
  master
  start_artwork_model
1.9.2@whisperme$ git checkout
1.9.2@whisperme$ git branch
  artwork_model
  artwork_model_localisation
  artwork_screen
* develop
  logger
  master
  start_artwork_model
1.9.2@whisperme$ pwd
/Users/tristan/Documents/DFR
1.9.2@whisperme$ 

非常感谢!
3个回答

13

我不太清楚为什么这个分支“消失”了,但不用担心,你的文件并没有丢失。

你可以通过多种方式找到它们:

  • 你可以使用 git checkout 命令离开匿名分支时打印的信息:"Previous HEAD position was 858491f"。
  • 你可以使用 git reflog 命令找到你的文件所在的提交。

然后你可以运行以下命令重新创建分支:

git checkout 858491f -b fixed_merge_conflict

然后您可以进行合并:

git checkout develop
git merge fixed_merge_conflict

如果您不关心分支,也可以在一步中完成合并:

git merge 858491f

1
你是一个救命恩人。 - demberto

0

出现了一些问题,你遇到了 分离头部的情况。我不确定在常规的git repo中如何引起这种情况,但是我使用git svn时遇到过这种情况(并且在这里提出了自己的解决方案)。可能是在创建新分支时没有--track跟踪上游repo。通常当你遇到detached head时,当你执行git branch时,你会看到(asterisk) (no branch)(不知道如何用markdown输入字面意义上的星号)。


links are rotten - innisfree

0

我曾经看到 git 分支似乎“消失”了,然后我意识到我在错误的目录中。在不同的目录中,git branch 会给出不同的结果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接