为什么git回复抱怨缺少-m选项? [英] Why does git revert complain about a missing -m option?

查看:612
本文介绍了为什么git回复抱怨缺少-m选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在与其他人一起开展一个项目,并且正在开发多个github分支。有人解决了一个问题,我把他的叉子合并,但后来我意识到我可以找到更好的解决方案。我想恢复我刚刚提交的提交。我试着用 git revert HEAD 来做这件事,但它给了我这个错误:

致命:Commit< ; SHA1>是一个合并,但没有给出-m选项。

这是什么意思?当我合并并提交时,我确实使用了-m选项来说合并到< username>。



我在这里做错了什么?

解决方案

默认情况下 git revert 拒绝恢复合并提交,因为实际上这意味着暧昧。我认为你的 HEAD 实际上是一个合并提交。



如果你想恢复合并提交,你必须指定您想要考虑的合并的哪个父母作为主干,即您想要恢复到的位置。



通常,这将是父母的第一位,例如,如果你在 master 并且做了 git merge unwanted ,然后决定还原不需要的。第一个父母将是您的合并前的 master 分支,第二个父母将是不需要的的提示。



在这种情况下,您可以这样做:

  git revert -m 1 HEAD 


So I'm working on a project with other people, and there's multiple github forks being worked on. Someone just made a fix for a problem and I merged with his fork, but then I realized that I could find a better solution. I want to revert the commit I just made. I tried doing this with git revert HEAD but it gave me this error:

fatal: Commit <SHA1> is a merge but no -m option was given.

What does that mean? When I merged and committed, I did use the -m option to say "Merged with <username>".

What am I doing wrong here?

解决方案

By default git revert refuses to revert a merge commit as what that actually means is ambiguous. I presume that your HEAD is in fact a merge commit.

If you want to revert the merge commit, you have to specify which parent of the merge you want to consider to be the main trunk, i.e. what you want to revert to.

Often this will be parent number one, for example if you were on master and did git merge unwanted and then decided to revert the merge of unwanted. The first parent would be your pre-merge master branch and the second parent would be the tip of unwanted.

In this case you could do:

git revert -m 1 HEAD

这篇关于为什么git回复抱怨缺少-m选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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