Git: "Interactive reverts"

Updated . Posted . Visible to the public.

If you need to revert only parts of one or several commits the following workflow can help:

If you need to revert multiple changes, make a branch and squash it afterwards.

For every commit you need to revert, starting at the most recent, do:

git revert -n [COMMIT] #revert, but don't automatically commit
... #fix any conflicts
git reset #unstage all changes
git add -p #this will ask you for every change, whether you want to go through with the revert (i.e. "y" will revert, "n" will not; "?" for help)
git commit
git reset --hard #throw away all changes you did not want to revert
Tobias Kraze
Last edit
Keywords
patch
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2010-11-11 09:40)