I usually submit a list of commits for review. If I have the following commits:
HEAD
Commit3
Commit2
git stash
+ rebase
automation
For when I need to modify an old commit a lot of times for Gerrit reviews, I've been doing:
git-amend-old() (
# Stash, apply to past commit, and rebase the current branch on to of the result.
current_branch="$(git rev-parse --abbrev-ref HEAD)"
apply_to="$1"
git stash
git checkout "$apply_to"
git stash apply
git add -u
git commit --amend --no-edit
new_sha="$(git log --format="%H" -n 1)"
git checkout "$current_branch"
git rebase --onto "$new_sha" "$apply_to"
)
GitHub upstream.
Usage:
git add
if already in repogit-amend-old $old_sha
I like this over --autosquash
as it does not squash other unrelated fixups.