Open
Description
When I am doing an interactive rebase, I may want to edit a commit:
pick 1249rya Foo bar
edit 1249rya Foo bar
pick 1249rya Foo bar
Annoyingly, I need to git undo --soft
afterwards to actually edit the commit. (Although git commit --amend
is valid too).
I later learned I can do:
pick 193472 Foo bar
exec git undo --soft
But commit message is lost, when I re-run git commit
, COMMIT_EDITMSG
is empty.
This alias, git redo
, combined with a git-hook, can re-populate the commit message:
[alias]
redo = !echo "$(git log -1 --format=%B HEAD)" > $GIT_DIR/LAST_COMMIT_MSG && git undo && git restore --staged $(git diff --name-only --staged --diff-filter=ard) > /dev/null 2>&1 || true && cat $GIT_DIR/LAST_COMMIT_MSG && echo '' && git -c advice.addEmptyPathspec=false add -N $(git ls-files --others --exclude-standard) > /dev/null 2>&1 || true
git hooks are documented here: https://stackoverflow.com/a/73981850/565877
Metadata
Metadata
Assignees
Labels
No labels