Skip to content

Instantly share code, notes, and snippets.

@Albert-IV
Created April 2, 2015 18:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Albert-IV/5b67ec0021371a0ad438 to your computer and use it in GitHub Desktop.
Save Albert-IV/5b67ec0021371a0ad438 to your computer and use it in GitHub Desktop.
Add `revert-file` to your git config, reverting all changes done in a commit to a specific file.
[alias]
revert-file = !sh /home/some-user/git-file-revert.sh
#!/bin/bash
output_help ()
{
echo "usage: git-revert-single-file <sha1> <file>"
}
sha1=$1
file=$2
if [ $sha1 ]; then
git diff $sha1..$sha1^ -- $file | patch -p1
else
output_help
fi
@Albert-IV
Copy link
Author

This was lifted / altered from the following StackOverflow links.

http://stackoverflow.com/a/2620822/23875
http://stackoverflow.com/a/1309674/23875

@mattcan
Copy link

mattcan commented Sep 28, 2016

This is super handy, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment