Reverting part of a commit with git

后端 未结 6 1869
闹比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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 16:17

    Personally, I prefer this version, which reuses the auto-generated commit message and gives the user the opportunity to edit and stick the word "Partially" in before finally committing.

    # generate a revert commit
    # note the hash printed to console on success
    git revert --no-edit 
    
    # undo that commit, but not its changes to the working tree
    # (reset index to commit-before-last; that is, one graph entry up from HEAD)
    git reset HEAD~1
    
    # interactively add reversions
    git add -p
    
    # commit with pre-filled message
    git commit -c 
    
    # reset the rest of the current directory's working tree to match git
    # this will reapply the excluded parts of the reversion to the working tree
    # you may need to change the paths to be checked out
    # be careful not to accidentally overwrite unsaved work
    git checkout -- .
    

提交回复
热议问题