What's the simplest way to amend a commit in order to revert the modifications made to a single file?

StackOverflow https://stackoverflow.com/questions/13993199

  •  11-12-2021
  •  | 
  •  

문제

Currently, when I have to do it, here are the steps that I follow:

  • Revert the commit (without creating a new commit, of course)
  • Reset all the modification introduced by the “revert,” except the one of the file that I wand to revert
  • Stage the reversal of the file which I want to revert and amend the last commit

Is there a more straightforward way to do that?

도움이 되었습니까?

해결책

Checkout the previous state of the file and amend the commit.

git checkout HEAD^ -- file.txt
git commit --amend

If you don't need to amend the commit log message the last command can be

git commit --amend -C HEAD

which doesn't even open your editor to edit the commit log, it just amends it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top