Skip to content

"git redo" (git undo --soft + pre-populate with last commit message) #1001

Open
@devinrhode2

Description

@devinrhode2

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions