Usage:
- Modify the file with the change you want
- Call
git-amend-old <sha>, replacing<sha>with the commit sha you want the change to apply to
| git-amend-old() ( | |
| # Stash, apply to past commit, and rebase the current branch on to | |
| of the result. | |
| # For Gerrit. | |
| https://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit/53$ | |
| 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" | |
| ) | |
| export -f git-amend-old |