Reverting part of a commit with git

后端 未结 6 1857
闹比i
闹比i 2020-12-22 15:21

I want to revert a particular commit in git. Unfortunately, our organization still uses CVS as a standard, so when I commit back to CVS multiple git commits are rolled into

6条回答
  •  一整个雨季
    2020-12-22 16:03

    I have used the following successfully.

    First revert the full commit (puts it in index) but don't commit.

    git revert -n   # -n is short for --no-commit
    

    Then interactively remove the reverted GOOD changes from the index

    git reset -p          # -p is short for --patch  
    

    Then commit reverse diff of the bad changes

    git commit -m "Partially revert ..."
    

    Finally the reverted GOOD changes (which have been unstaged by the reset command) are still in the working tree. They need to be cleaned up. If no other uncommitted changes are left in the working tree, this can be done by

    git reset --hard
    

提交回复
热议问题