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
git status
) - 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 (-v
). - You can now push your changes with:We need
git push --force-with-lease
--force-with-lease
to “confirm to the server that we really want to edit the last commit”.
Caution
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-lease
protects 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.
Liked this post? Subscribe:
Discussions
This blog does not host comments, but you can reply via email or participate in one of the discussions below: