Skip to content

Instantly share code, notes, and snippets.

@azu
Last active October 14, 2023 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/824c4f96a6eabababb7bd4034dc053d5 to your computer and use it in GitHub Desktop.
Save azu/824c4f96a6eabababb7bd4034dc053d5 to your computer and use it in GitHub Desktop.
Gitメモ: メモをコミットして作業ツリー自体はメモを書く直前に戻すcommit -hook
# 📝 [Note] Mode -- if commit message starts with "📝" or includes "[Note]"
IS_NOTE_MODE=$(git log -1 --pretty=%B | grep -E '^(📝|\[Note\])')
if [[ -n "${IS_NOTE_MODE}" ]]; then
# メモの作業内容を戻すコミットをする
headSHA=$(git rev-parse HEAD)
git revert --no-commit HEAD
git ls-tree -r --name-only HEAD | xargs git commit -m "↩️ ${headSHA}" --
# メモを書く直前の状態に作業内容を戻す
git revert --no-commit HEAD
# terminal notification
# remove 📝 and [Note]
trimCommitMesasge=$(echo "${GIT_COMMIT_MSG}" | sed -e 's/📝//' -e 's/\[Note\]//')
osascript -e "display notification \"${trimCommitMesasge}\" with title \"📝 メモを記録\""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment