问题描述
因此,我的一位同事偶然合并,实际上只保留了树的一面。所以他开始了合并,删除了合并引入的所有更改,然后提交了合并。这是一个简单的测试用例,我在测试回购上做了一个测试。这个回购有三个分支。 idx是意外合并的主题分支,master是主线。 dev只是一个测试-m是如何工作的,所以你可以忽略它。
我想要做的是恢复错误的合并。所以从大师我尝试运行 git revert -m 1 ,但随后git响应:
#关于分支大师
没有提交(工作目录清理)
所以它实际上并没有创建撤消合并的恢复提交。我相信会发生这种情况是因为合并实际上并未包含任何实际更改。
如果您想玩我的测试回购,可以从
这是一个git错误,还是我错过了什么?
这里最好的经验法则是永远不会改变历史你的回购已经公开。它真的搞砸了。虽然我不认为这种情况可以避免它。
我认为这里有几个选项,但最简单的是做一个rebase。使用你的仓库,这些是我使用的命令:
git rebase -i ead3646
然后,当交互式shell弹出时,删除整行错误提交。除此之外,你应该结束新历史记录:
* f0ab6d5更正常的工作on dev
* ebb5103 idx commit
ead3646 master change
* 582c38c dev commit
* f4b8bc6 initial commit
让你们两个(和其他人)重新同步将需要一些分支,推送,电子邮件和午餐购买。
So one of my coworkers accidentally made a merge that actually only kept one side of the tree. So he started a merge, deleted all the changes introduced by the merge, and then committed the merge.
Here is a simple test case I did on a test repo. This repo has three branches. idx is the topic branch that was accidentally merged, and master is the mainline. dev is just a test of how revert -m works so you can ignore it.
What I want to do is revert the faulty merge. So from master I try to run git revert -m 1 <sha1sum of faulty merge>
but then git responds with:
# On branch master
nothing to commit (working directory clean)
So it doesn't actually create a revert commit that undoes the merge. I believe that this happens because the merge didn't actually contain any real changes.
If you want to play around with my test repo you can download it from here
Is this a git bug, or am I missing something?
The best rule of thumb here is to never ever change the history of your repo after it has been made public. It really screws things up. I don't think this case can avoid it though.
I think there are a couple of options here but the simplest is to do a rebase. Using your repo, these are the commands I used:
git rebase -i ead3646
Then, when the interactive shell comes up, remove the entire line of the faulty commit. Save that and you should wind up with a new history like this:
* f0ab6d5 more normal work on dev
* ebb5103 idx commit
* ead3646 master change
* 582c38c dev commits
* f4b8bc6 initial commit
Getting you two (and others) back in sync is going to take some branching, pushing, emailing and lunch buying.
这篇关于你如何恢复错误的git合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!