git revert <hash>由于合并而不允许,但没有给出 -m 选项 [英] git revert <hash> not allowed due to a merge but no -m option was given

查看:50
本文介绍了git revert <hash>由于合并而不允许,但没有给出 -m 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用revert"命令将 git 中的某个哈希"数字还原.

I am trying to revert to a certain 'hash' number in git, by using the 'revert' command.

我正在使用以下命令:

git revert c14609d74eec3ccebafc73fa875ec58445471765

但是,我得到以下返回:

But, I am getting the following returned:

错误:提交 c14609d74eec3ccebafc73fa875ec58445471765 是一个合并,但没有给出 -m 选项.
致命:恢复失败

error: Commit c14609d74eec3ccebafc73fa875ec58445471765 is a merge but no -m option was given.
fatal: revert failed

作为一个新的 git 用户,请你解释一下发生了什么 &我必须做些什么来解决这个问题.

As a new git user, please can you explain what is happening & what I have to do to resolve this.

我想恢复到我在运行 git log 时看到的这个特定提交 (c14609d74eec3ccebafc73fa875ec58445471765).

I want to revert back to this certain commit (c14609d74eec3ccebafc73fa875ec58445471765) that I see when running git log.

推荐答案

您正在尝试还原合并提交,而 git 不知道要还原到哪个父级.-m 允许我们选择要选择的父级.查看合并提交并记下您要转到哪个父级.父信息可以在git log中看到,例如:

You are trying to revert a merge commit, and git doesn't know which parent to revert to. The -m allows us to choose which parent to choose. See the merge commit and note down which parent you want to go to. The parent information can be seen in git log, for example:

提交 d02ee0f2179def10277f30c71c5d6f59ded3c595

commit d02ee0f2179def10277f30c71c5d6f59ded3c595

合并:dd3a24c 2462a52

Merge: dd3a24c 2462a52

然后运行:

git revert <hash> -m 1

其中 1 表示父编号 1 (dd3a24c).

where 1 indicates parent number 1 (dd3a24c).

如果你试图恢复那个提交,请执行:

If you are trying to revert to that commit, do:

git reset --hard <hash>

从文档中了解 git revertgit reset 之间的区别并决定您想要哪个.git revert 是更安全的选择,但并没有真正做到你想要的.它只是还原(一组)提交的更改.git reset 使您移动到历史记录中的特定提交,并将重写您的历史记录.

Understand the difference between git revert and git reset from the docs and decide which one you want. git revert is the safer option, but doesn't really do what you want. It just reverts the changes of a (set of) commit. git reset makes you move to a particular commit in history, and will rewrite your history.

这篇关于git revert &lt;hash&gt;由于合并而不允许,但没有给出 -m 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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