Created
April 2, 2015 18:46
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
revert-file = !sh /home/some-user/git-file-revert.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This is super handy, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was lifted / altered from the following StackOverflow links.
http://stackoverflow.com/a/2620822/23875
http://stackoverflow.com/a/1309674/23875