Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert changes to a specific file from a specific commit

Tags:

git

A few weeks ago (i.e. many commits ago), I made a git commit that touched many files. Most of the commit was great.

However, I'd now like to undo the changes that I'd made to just one of those files, but I don't want to override any changes that had been made to that file after that commit.

Is there a way for me to revert a specific commit but only on one of the files in that commit?

like image 359
Ryan Avatar asked May 29 '14 23:05

Ryan


1 Answers

Get a patch-ready diff for that file in that commit, and then reverse-apply the patch:

git show <commit-id> -- <path> | git apply -R -

Make sure you like the result, and if so, add and commit with appropriate message.

like image 77
torek Avatar answered Oct 08 '22 07:10

torek