Last active
August 29, 2015 14:00
-
-
Save Larusso/11209840 to your computer and use it in GitHub Desktop.
git reset with pattern
This file contains 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
e() | |
{ | |
echo $1 | grep -E $2 | grep -E '(^M\s|^D\s|^R\s)' | cut -c 3-; | |
} | |
f() | |
{ | |
git st --porcelain | while read line | |
do | |
file=$(e "$line" $1) | |
file=${file//\"/}; | |
if [ ! -z "$file" -a "$file" != " " ] | |
then | |
echo "reset file: $file" | |
git reset HEAD "$file" > /dev/null | |
git checkout "$file" | |
fi | |
done | |
} | |
if [ $# = 1 ] | |
then | |
GIT_ROOT=`git rev-parse --show-toplevel` | |
(cd "$GIT_ROOT" && f $@) | |
else | |
echo "usage: git reset-pattern <pattern>" >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment