Skip to content

Instantly share code, notes, and snippets.

@xphere
Last active March 24, 2022 07:45
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 xphere/cb03e51a456112afe94c3f7cbe1bd9e0 to your computer and use it in GitHub Desktop.
Save xphere/cb03e51a456112afe94c3f7cbe1bd9e0 to your computer and use it in GitHub Desktop.
Allows to store/recover state of current git branch. Like stash but keeping index and branch tracking.
[alias]
index-is-clean = !git diff-index --cached --quiet HEAD
recover = !f() { local REV=$(git rev); [ "$(git commit-message)" = ::modified ] && git reset -q HEAD~; [ "$(git commit-message)" = ::indexed ] && git reset -q --soft HEAD~; [ $(git rev) = $REV ] || echo 'Current state recovered'; }; f
rev = rev-parse HEAD
store = !f() { local REV="$(git rev)"; git index-is-clean || git unsafe-commit '::indexed'; git working-is-clean || $(git add -A && git unsafe-commit '::modified'); [ "$(git rev)" = "$REV" ] || echo 'Current state stored'; }; f
unsafe-commit = !git commit --no-verify -q -m
working-is-clean = !git diff-files --quiet && [ -z "$(git ls-files --exclude-standard --others)" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment