Skip to content

Instantly share code, notes, and snippets.

@schlueter
Last active September 8, 2015 15:24
Show Gist options
  • Save schlueter/d9669e15776f9cf56489 to your computer and use it in GitHub Desktop.
Save schlueter/d9669e15776f9cf56489 to your computer and use it in GitHub Desktop.
Helpful git one liners
# When you want the original versions of files during a rebase
git status | awk '/(both added|both modified):/ {
sub(/(both added|both modified):/, ""); print $1
}' | xargs -n1 git checkout $(git show | awk ' /commit/ { print $2 }')
# When you don't want files added during a rebase
git status | awk '/added by them:/ {
sub(/added by them:/, ""); print $1
}' | xargs -n1 git rm
# When you want to know what happened in the last day and can't find it
for obj in $(find .git/objects -type f -mtime -1); do
echo ---------$obj---------
git cat-file -p $(basename $(dirname $obj))$(basename $obj)
echo
done
# Remove all merged branches
git branch --merged | awk '!/\*/' | xargs -n1 git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment