Revert changes to a file in a commit

后端 未结 8 1933
無奈伤痛
無奈伤痛 2020-12-12 09:45

I want to revert changes made by a particular commit to a given file only.

Can I use git revert command for that?

Any other simple way to do it?

8条回答
  •  离开以前
    2020-12-12 10:17

    git reset HEAD^ path/to/file/to/revert/in/commit
    

    The above command will take file out of commit, but it will reflect in git status.

    git checkout path/to/file/to/revert/in/commit
    

    The above command will revert the changes (as a result you get file same as HEAD).

    git commit
    

    (Pass --amend to amend commit.)

    git push
    

    With this, the file which is already in the commit is removed and reverted.

    The above steps should be followed from the the branch where the commit is made.

提交回复
热议问题