Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
devinrhode2 opened this issue Oct 17, 2022 · 0 comments
Open

Comments

@devinrhode2
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant