Can I do a partial revert in GIT

后端 未结 4 1005
迷失自我
迷失自我 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:30

    You can interactively apply old version of a file using the checkout command.

    For example, if you know the COMMIT where the code to add back was removed, you can run the following command:

    git checkout -p COMMIT^ -- FILE_TO_REVERT
    

    Git will prompt you to add back the hunks that are missing from the current version of the file. You can use e to create a patch of the change before applying it back.

提交回复
热议问题