Delete a commit but keep the changes
Let's say I have a commit history like this:
commit 1 - The first commit
commit 2 - The commit I want to revert, but keep the changes of
commit 3 - The third commit
commit 4 - The fourth commit
[uncommited work]
If I haven't pushed anything yet (or only up to commit 1), how can I delete commit 2, but apply the changes made in commit 2 to the currently uncommited work?
All I could find was about how to delete the commit and it's changes or reset to that commit, which would (as I understand) remove all commits afterwards from the history.
I would reorder the revisions the way you want, then cherry-pick commit 2, stash pop and then set the HEAD pointer to "rebuilt" commit 4:
git stash save "will come back"
git checkout commit1
git cherry-pick commit2..commit4
git cherry-pick commit2
git stash pop
git reset --soft HEAD~1
That should do
I believe git rebase -i HEAD~3
should do the trick.
You'll then be able to select commit 2 to edit, change the contents of the commit or the files that have been changed, then git will 'replay' commit 3 and 4 on top of the edited commit 2
链接地址: http://www.djcxy.com/p/49812.html下一篇: 删除提交但保留更改