Skip to content

Instantly share code, notes, and snippets.

@cdunham
Last active May 16, 2026 01:17
Show Gist options
  • Select an option

  • Save cdunham/47d7b6e7959432a5c4177d9dd99cf0f2 to your computer and use it in GitHub Desktop.

Select an option

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 1
fi
case `git cat-file -t $1` in
commit) ;;
*)
echo "$1 is not a git commit"
exit 1
;;
esac
SHA=$1
git read-tree $SHA^{tree}
git commit -C $SHA | head -n1
git reset --hard --quiet
@leoger

leoger commented May 15, 2026

Copy link
Copy Markdown

Thanks for putting this together. Sorry I'm late to the party, but wouldn't one actually want exit 1 in those failure cases so that interactive rebase pauses rather than silently dropping the commit? :-\

@cdunham

cdunham commented May 15, 2026

Copy link
Copy Markdown
Author

Hi Leo, that's a great idea. I've made the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment