简体   繁体   English

将母版合并还原到功能分支

[英]Revert merge of master to feature branch

I have a tracking branch to which I merged my master branch. 我有一个跟踪分支,我在其中合并了我的master分支。 There were conflicts that I fixed, committed and pushed. 我解决,犯下并推了一些冲突。 Now I need to revert that merge. 现在,我需要还原该合并。 How do I do it? 我该怎么做? I tried checking log, but obviously the history from master is now in the feature branch. 我尝试检查日志,但是显然来自master的历史记录现在位于Feature分支中。 Is there any hope? 有希望吗?

From my understanding, it looks like you want to revert on your feature branch the merge commit that merged from your master branch. 据我了解,您似乎想在功能分支上还原从主分支合并的合并提交。

You can do this in 2 ways, one which is more safe. 您可以通过2种方式执行此操作,一种更安全。

  1. git revert -m <parent_index> HEAD

To get the parent index, run git show <merge commit SHA1> and see the index (1-based) of the commit you want to revert to. 要获取父索引,请运行git show <merge commit SHA1>并查看要还原到的提交的索引(从1开始)。

  1. git reset --hard <feature branch SHA1>

This isn't the better option because it resets your history and you won't be able to get back to the merge commit even if you wanted to. 这不是更好的选择,因为它会重置您的历史记录,并且即使您愿意也无法返回到合并提交。

I suggest using the first one because you get to keep track of the merge commit, in case you want to see how you merged something later on. 我建议使用第一个,因为您可以跟踪合并提交,以防日后想要查看如何合并某些内容。

git reset --hard <sha of last commit of feature branch>

We consider ur move is a merge commit. 我们认为您的举动是合并提交。 It will revert to feature branch and trash the merge commit. 它将恢复为功能分支,并丢弃合并提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM