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. 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"). 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.
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)
精彩评论