tj / tj/git-extras

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

Open
#1,001 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
18.1k
Forks
1.2k
Avg merge
5d 17h
Merged PRs (30d)
1

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing git-extras command entry points and any tests for git undo or aliases. Compare the requested git redo behavior with the interactive-rebase and git-hook flow described here; done means the command restores the prior commit message while preparing the working tree for editing.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, shell
Domain
cli, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.