I often do this:
git add -u
git commit
…discover mistake, fix it…
git add -u
git commit -m "Fix typo"
Is there an easy way to squash the second commit back into the first? Sometimes I can do it with git rebase -i, but sometimes I just get a message about being up to date.
Note I’m only really talking about situations where I haven’t pushed the first commit. Basically I want to use the first log message, but with the combined effect of the two commits. Can I use git commit --amend for such things?
This related question kind of dealt with this:
git: squash/fixup earlier commit
The best answer is a year old though, and I wonder if things have improved?
This is exactly what
git commit --amendis for. Given your example, all you need to do is add the--amendflag to your second commit:…discover mistake, fix it…
You can do this visually in
git guialso (there is a radio-box to toggle between “new commit” and “amend last commit”)