Skip to content

Instantly share code, notes, and snippets.

@cdunham
Created May 24, 2020 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdunham/47d7b6e7959432a5c4177d9dd99cf0f2 to your computer and use it in GitHub Desktop.
Save cdunham/47d7b6e7959432a5c4177d9dd99cf0f2 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
# git snap: (re-)commit a snapshot of exactly another commit
# an alternative to 'pick' in git rebase -i: use x git snap <sha>
if [ -z "$1" ]; then
echo "usage: git snap <commit sha1>"
exit
fi
case `git cat-file -t $1` in
commit) ;;
*)
echo "$1 is not a git commit"
exit
;;
esac
SHA=$1
git read-tree $SHA^{tree}
git commit -C $SHA | head -n1
git reset --hard --quiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment