git 中神秘消失的分支

发布于 2024-10-13 09:31:07 字数 2802 浏览 4 评论 0原文

以下是我执行的一些 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$ 

非常感谢!

Here are some git actions I performed. As you can see, I made a new branch, modified my files, and then committed the changes. After changing back to another branch, hoping to merge, the branch I was just working on disappeared.

Does anyone know how I can recover the files from fixed_merge_branch? I'm freaking out!

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$ 

Thanks a bunch!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

守护在此方 2024-10-20 09:31:07

好吧,我不明白为什么分支“消失”,但不用担心,你的文件没有。

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

  • 您可以使用离开匿名分支时 git checkout 打印的消息:“上一个 HEAD 位置为 858491f”。
  • 您可以使用 git reflog 并查找文件的提交。

然后你可以运行它来重新创建分支:

git checkout 858491f -b fixed_merge_conflict

然后你可以进行合并:

git checkout develop
git merge fixed_merge_conflict

或者如果你不关心分支,你可以一步进行合并:

git merge 858491f

Well I don't exactly see why the branch 'disappeared' but don't worry, your files didn't.

You can find them by many means:

  • You can use the message printed by the git checkout when you left your anonymous branch: "Previous HEAD position was 858491f".
  • You can use git reflog and find the commit of your files.

Then you can run this to recreate the branch:

git checkout 858491f -b fixed_merge_conflict

and then you can do your merge:

git checkout develop
git merge fixed_merge_conflict

Or you can do the merge in one step if you don't care about the branch:

git merge 858491f
从﹋此江山别 2024-10-20 09:31:07

由于某种原因,您会遇到分离头情况< /a>.我不完全确定这是如何在常规 git 存储库中引起的,但我使用 git svn 遇到过它(并在这里提出了我自己的解决方案)。当您创建新分支时,可能没有 --track 上游存储库。通常当你得到一个分离的头时,当你执行git分支时,你会看到(星号)(无分支)(不要知道如何用 Markdown 制作字面上的星号)

for some reason, you're getting a detach head situation. I'm not entirely sure how that is caused in a regular git repo, but i've encountered it using git svn (and came up with my own solution here). It might be that the aren't --tracking the upstream repo when you create a new branch. Usually when you get a detached head, when you do a git branch, you will see (asterisk) (no branch) (don't know how to do a literal asterisk with markdown)

谜兔 2024-10-20 09:31:07

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

I've seen git branches seem to "disappear", then I realized I was in the wrong directory. git branch will give different results in different directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文