Can I do a partial revert in GIT

后端 未结 4 1016
迷失自我
迷失自我 2020-12-22 15:34

Is it possible to revert only a single file or certain changes in a file in multi file commit?

Full story I committed a bunch of files. A number of

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 16:08

    You can revert the commit without creating a new one by adding the '--no-commit' option. This leaves all the reverted files in the staging area. From there, I'd perform a soft reset and add in the changes I really wanted. For an example workflow:

    git revert  --no-commit
    git reset   // This gets them out of the staging area
    
    git add 
    git checkout . // This wipes all the undesired reverts still hanging around in the working copy
    git commit
    

提交回复
热议问题