Example, I don't want to hard-code the string "load_more" so am going to redo/tweak those commits:
git rebase --exec 'git difflastcommitadded | ag load_more && { echo "found load_more"; git redo; } || echo "ok"' --no-reschedule-failed-exec -i 315abbd5b
Setup:
- Install
ag (brew install the_silver_searcher) (grep/ack alternative)
- Add this git
difflastcommitadded alias:
git config --global --edit
brew install the_silver_searcher
Paste:
[alias]
# From: https://stackoverflow.com/questions/73981158/git-rebase-make-bad-name-in-large-pr-stack-disappear/73981159#73981159
difflastcommitadded = !git diff HEAD^..HEAD --no-ext-diff --unified=0 --exit-code -a --no-prefix | egrep '^\\+'
Alternatively, if you want to completely abolish a variable name from a folder in your repo, continue reading this less flexible example:
git rebase --exec 'ag -0 -l AccountNode ui/app && git redo || echo "ok"' -i 315abbd5b
This will rebase, but stop whenever there's a commit that introduced AccountNode inside the ui/app folder, undo that commit, and pop those changes into your working directory, so you can fix that in your ide.
Once you fix an instance of AccountNode you can proceed with nice safety checks using this script:
ag -0 -l AccountNode ui/app/pages/AccountManagement2 && echo "still contains AccountNode" || {
yarn --cwd ui run jest -i && git add . && git commit && git rebase --continue
}
In my instance, git commit runs prettier+eslint, but not tests (those run in ci right now)
This depends on the git redo alias mentioned here: git rebase - pop each commit into working dir to easily edit, re-use commit msg