简体   繁体   English

如何在不搞砸Git历史的情况下退出一系列更改

[英]How do I back out a series of changes without screwing up history in git

I want to undo some changes without removing them from the history, in a group-friendly way. 我希望以一种对群体友好的方式撤消一些更改而不将其从历史中删除。 Currently, I have this (* indicates master): 目前,我有这个(*表示主人):

[rev 1] -- [rev 2] -- [rev 3] -- [rev 4] -- [rev 5] -- [*rev 6]

I want to get back to rev 2, but in a way that makes sense. 我想回到第2版,但是以一种有意义的方式。 I believe it should look like this: 我相信它应该是这样的:

[rev 1] -- [rev 2] -- [rev 3] -- [rev 4] -- [rev 5] -- [rev 6] -- [*rev 7]
               |                                                   |
               \---------------------------------------------------/

Where rev 7 is the merge of 6 and 2 (and the "merge" is really just "blindly keep rev 2"). 其中rev 7是6和2的合并(并且“合并”实际上只是“盲目保持rev 2”)。 No new heads are created. 没有创建新头。 How do I do this? 我该怎么做呢?

Thanks in advance. 提前致谢。

You would 你会

git branch temp
git reset --hard rev2
git reset --soft temp
git add -A
git commit -m "this commit makes all the changes so that the tree at rev7 looks like the tree at rev2"
git branch -d temp

There is a good post by Scott Chacon about the modifiers (hard, soft and mixed) on the reset command and others. Scott Chacon有一篇关于reset命令和其他修饰符(硬,软和混合)的文章。

without a temp branch, you could: 没有临时分支,你可以:

git reset --hard rev2
git reset --soft HEAD@{1}
git add -A
git commit -m "this commit makes all the changes so that the tree at rev7 looks like the tree at rev2"

If you want a merge there, you could just: 如果你想在那里合并,你可以:

git merge --no-ff -s ours rev2

(careful, this is different than the recursive strategy with the "ours" option) (小心,这与带有“我们的”选项的递归策略不同)

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

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