修正错误合并后的Git回购 [英] Fixing Git repo after incorrect merging

查看:76
本文介绍了修正错误合并后的Git回购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多独立的分支,我想合并它们,因为它们都是程序不同部分的更新。



我想我应该合并它们,但是在每个分支出来之后,我运行了 git commit -a

然后,

然后我意识到整个程序及时回来了,所以我运行了一个 git reset --soft HEAD (我在某篇文章中读到了这个应该会有所帮助),但那并没有,我也从git那里得到了关于手动删除一些 ./ git / index.lock 的消息。所以我把它移动到 ./git / backup_of_index.lock ,但是这似乎也没有做任何事情。



如何修复我的仓库并合并所有分支? 在这种情况下,最重要的git命令是< a href =http://www.kernel.org/pub/software/scm/git/docs/git-reflog.html =nofollow noreferrer> git reflog 。 reflog会跟踪每个特定分支头的所有更改,并且 git reflog 命令会列出分支头的所有更改。



如果您可以使用reflog标识一个好的提交ID(并且它会在那里,某处),那么您现在就领先于现在的位置。如果一个好的提交ID是 abc123 ,那么命令:

  git checkout -b rescue abc123 

创建一个名为 rescue 在提交ID abc123



当我学习git时,我有类似的排序我在哪里,我怎么到这里来的?时刻。我了解了有关不同堆栈溢出问题的reflog,它是最有价值的有关Git的知识。


I had a bunch of separate branches, and I wanted to merge them, as each of them was an update to a different part of the program.

I guess I was supposed to merge them but instead I ran a git commit -a after cheking out each branch.

Then I realized the whole program went back in time, so I ran a git reset --soft HEAD (I read in an article somewhere that this should help), but that didn't do anything.

I also got this message from git about manually removing some ./git/index.lock so I moved it to ./git/backup_of_index.lock, but that didn't seem to do anything, either.

How do I fix my repository and merge all the branches?

解决方案

The most important git command in this situation is git reflog. The reflog tracks all changes to each particular branch head, and the git reflog command lists all of the changes to the branch head going back in time.

If you can identify a "good" commit id using the reflog (and it will be there, somewhere), then you are way ahead of where you are now. If a good commit id is say, abc123, then the command:

git checkout -b rescue abc123

creates a new branch called rescue at the commit id abc123.

When I was learning git, I had a similar sort of "where the heck am I and how did I get here?" moment. I learned about the reflog on a different Stack Overflow question, and it's been the most valuable thing to know about Git.

这篇关于修正错误合并后的Git回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆