So I have an old file repo/foo.txt

foo.txt has undergone many changes over the years.

Recently, I changed something in commit Z.

Later on, others changed foo.txt again in commits Y, X.

Now, I've been put to the task of "undoing" the changes I made to foo.txt in 
commit Z.

I changed other files as well in commit Z, so I can't do git revert Z.

The Google answer is to do git checkout Z^ (the commit before Z). But then I 
lose the changes committed in Y and X.

I also can't rewrite the history here, because the repo is published all 

*Solution 1:*
I could do a git revert, then do a reset, commit foo.txt only, and drop the 
changes in the other files. 

*Solution 2:*
git diff -R Z foo.txt > revert.diff
git apply revert.diff 

I think both solutions above are too cumbersome. Isn't there a smooth way to 
do something like git revert [SHA] [path] ?

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to