Sometimes when your pull request is reviewed, it turns out that you have to make a small change. For instance, you have to remove a white space. Here is a really quick way to fix it, that will not even fire your editor to change the commit message.
- Make sure you are on the branch of the pull request (for instance, by reading the output of
- Edit and save your file, removing the white space.
- Then in your terminal, use:
This edits (
git commit --amend -a -v -C HEAD
--amend) your last commit, adding all the changes made to files (
-a) and reusing the last commit message (
-C HEAD). Once this is done, a summary is printed (
- You can now push your changes with:
git push --force-with-lease
--force-with-leaseto “confirm to the server that we really want to edit the last commit”.
Two words of caution with this technique:
- you are rewriting history, if anyone has made changes on top of yours, they will face a confusing situation when they try to merge your changes again.
force-with-leaseprotects us somewhat, as the push will fail if someone else has pushed changes on top of ours, but it won’t help if the other person’s changes are local.
- in most situations, commit messages (and their content), should be crafted as an easy to review progression. Abusing this trick could make commits harder to review.