Reputation: 9464
Consider the following unpushed commits:
97874cd commit 5
13bc8cf commit 4
60c37d4 commit 3
0c29771 commit 2
6db9ba4 commit 1
How do I remove commit 3 without touching any files at all and keeping commit 4 and 5 intact?
Upvotes: 1
Views: 104
Reputation: 3589
Do you intend to keep the changes of commit 3, but have it disappear from your history? Then you should make an interactive rebase like so:
git rebase -i HEAD~4
And then mark 60c37d4 to be smashed
or fixed
during the rebase.
If you want to remove the changes of commit3 as well, delete the corresponding line in the interactive rebase. Another way to accomplish the latter is
git rebase --onto HEAD~3 HEAD~2 HEAD
Upvotes: 2
Reputation: 12795
One way would be:
git checkout -B new_branch
git reset --hard 0c29771
git cherry-pick 13bc8cf
git cherry-pick 97874cd
git checkout master
git reset new_branch
This will result in files in the same state as before any of these, but the changes of commit 3 will be uncommitted (assuming it all goes without any conflicts).
Upvotes: 1