Skip to content

Instantly share code, notes, and snippets.

@Larusso
Last active August 29, 2015 14:00
Show Gist options
  • Save Larusso/11209840 to your computer and use it in GitHub Desktop.
Save Larusso/11209840 to your computer and use it in GitHub Desktop.
git reset with pattern
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