还原通过合并所做的更改 [英] Revert changes made by merge

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

问题描述

开发人员正在对两个文件进行小的更改.但是在此提交期间,他发生了合并冲突,从而删除了很多东西(可能没有最新的版本).然后将其推送到共享存储库,其他一些开发人员进行了其他提交.

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?

我正在尝试git revert commitsha,但是并没有带来更改.我是否需要还原mergesha?我该如何确定?

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?

推荐答案

git revert --mainline

通常:

git revert --mainline 1 dd8cbe3e4

位置:

  • dd8cbe3e4是您要撤消的错误合并提交,并且
  • --mainline告诉您要还原的是先前的多个提交中的哪一个(请记住,合并提交具有多个父提交,您只能保留其中一个).
    • 对于1的含义我找不到很好的解释,但我的猜测是1,2,3...对应于紧接dd8cbe3e4之前提交的映射列表,并按 ascending 排序时间顺序(最早的顺序-通常是您要还原的顺序).
    • dd8cbe3e4 is the bad merge commit you want to undo, and
    • --mainline tells you which of the multiple previous commits is the one to restore (remember, a merge commit has multiple parent commits and you can only keep one of them).
      • 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).

      来源:

      http://thezencoder.com/2013/09/05/如何正确还原a-bad-merge-in-git/

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

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