The git rebase command with --exec
flag can be pretty handy in a variety of situations. Using this, you can execute any git command on a range of commits, both for local and remote commits.
One example that this can be really handy for is modifying commit details.
git rebase HEAD~2 --exec "git commit --amend --no-edit --author='FirstName LastName <author@gmail.com>'"
The above commit modifies the author details on the last 2 commits in the current branch. --no-edit
flag ensures this gets executed right away without showing the edit prompt for each commit.
This can be followed up with a force push git push -f
on the current branch to modify remote commits.