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

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

问题描述

所以我正在与其他人一起进行一个项目,并且有多个 github 分支正在处理中.有人刚刚修复了一个问题,我与他的叉子合并,但后来我意识到我可以找到更好的解决方案.我想恢复我刚刚所做的提交.我尝试用 git revert 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.

这是什么意思?当我合并并提交时,我确实使用了 -m 选项来表示与 <用户名> 合并".

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

我在这里做错了什么?

推荐答案

默认情况下 git revert 拒绝还原合并提交,因为这实际上意味着不明确.我认为您的 HEAD 实际上是一个合并提交.

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.

通常这将是第一个父级,例如,如果您在 master 上并执行了 git 合并不需要的,然后决定恢复 unwanted<的合并/代码>.第一个父级将是您的合并前 master 分支,第二个父级将是 unwanted 的提示.

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 cat-file -p [MERGE_COMMIT_ID] 将按顺序显示父分支.列出的第一个是 -m 1,第二个是 -m 2.

git cat-file -p [MERGE_COMMIT_ID] will show the parent branches in order. The first one listed would be -m 1, the second -m 2.

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

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