恢复合并所做的更改 [英] Revert back changes made by merge

查看:101
本文介绍了恢复合并所做的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发人员对两个文件进行了小改动。但是在这个提交过程中,他有一个合并冲突,它删除了很多东西(可能没有最新的最新版本)。然后它被推送到共享库和其他一些开发者做了一些其他的提交。

现在,我们注意到合并删除了重要的文件,我们想要恢复它返回。

我怎样才能做到这一点,而不会丢失从下一次提交更改?



我试图 git恢复commitsha ,但它没有带回更改。我是否需要还原 mergesha

解决方案

通常:

  git revert --mainline 1 dd8cbe3e4 

其中:




  • dd8cbe3e4 是您要撤消的错误合并提交,并且
  • - mainline 告诉你以前的多个提交中哪一个是要恢复的状态(记住,合并提交具有多个父提交并且不像人类没有首选父母,所以你需要告诉它你喜欢哪个父母)。


    • 我无法找到 1 的含义,但我的猜测是 1,2,3 ... 对应于紧接在 dd8cbe3e4 之前的提交的映射列表,按升序按时间顺序排列(最早的第一个 - 这通常是您想要还原的内容)。




来源:

http://thezencoder.com/2013/09/05/how-to-correctly-revert-a-bad-merge-in- git /


The developer was commiting small changes to two files. But during this commit, he had a merge conflict which deleted a lot of stuff (probably didn't have the last up to date version). Then it was pushed to the shared repo and some other developers did some other commits.

Now, we noticed, that the merge deleted the important files, and we want to revert it back.
How can I do this without losing the changes from the next commits?

I was trying to git revert commitsha, but it didn't bring the changes back. Do I need to revert back the mergesha? How can I determine it?

解决方案

Generally:

git revert --mainline 1 dd8cbe3e4

Where:

  • dd8cbe3e4 is the bad merge commit you want to undo, and
  • --mainline tells you which of the multiple previous commits is the one to consider as the one whose state to restore (remember, a merge commit has multiple parent commits and unlike humans doesn't have a preferred parent, so you need to tell it which parent you prefer).
    • I can't find a good explanation of what the 1 means, but my guess is that 1,2,3... corresponds to a list of mappings to the commits immediately before dd8cbe3e4, sorted by ascending chronological order (oldest first - which is usually what you want to revert to).

Source:

http://thezencoder.com/2013/09/05/how-to-correctly-revert-a-bad-merge-in-git/

这篇关于恢复合并所做的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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