Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

git - 如何还原已经推送到远程分支的合并提交?(How to revert a merge commit that's already pushed to remote branch?)

git revert <commit_hash> alone won't work.

(单独使用git revert <commit_hash>无效。)

-m must be specified, and I'm pretty confused about it.

(-m必须被指定,对此我感到很困惑。)

Anyone experienced this before?

(有人经历过吗?)

  ask by Yaz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The -m option specifies the parent number .

(-m选项指定父编号 。)

This is because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.

(这是因为合并提交有多个父项,而Git不自动知道哪个父项是主线,哪个父项是要取消合并的分支。)

When you view a merge commit in the output of git log , you will see its parents listed on the line that begins with Merge :

(当您在git log的输出中查看合并提交时,您会看到其父级在以Merge开头的行中列出:)

commit 8f937c683929b08379097828c8a04350b9b8e183
Merge: 8989ee0 7c6b236
Author: Ben James <ben@example.com>
Date:   Wed Aug 17 22:49:41 2011 +0100

Merge branch 'gh-pages'

Conflicts:
    README

In this situation, git revert 8f937c6 -m 1 will get you the tree as it was in 8989ee0 , and git revert -m 2 will reinstate the tree as it was in 7c6b236 .

(在这种情况下, git revert 8f937c6 -m 1将让你的树,因为它是在8989ee0git revert -m 2将恢复树,因为它在7c6b236 。)

To better understand the parent IDs, you can run:

(为了更好地了解父ID,可以运行:)

git log 8989ee0 

and

(和)

git log 7c6b236

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...