When I work, I often meet with this workflow:
This workflow has a disadvantage: it generates a dummy commit in my system. My question is: how can I avoid this situation? For example, when I come back to work, I will cancel previous commit?
In addition to the two existing answers (git reset
and git stash
), I personally just ignore the extra commit (which almost has a commit message of wip
...) until I'm ready to push the change somewhere remote, e.g. to github to create a pull request.
At that point, I use git rebase -i
to look at all the commits I've got in that branch, and work out which commits I want to push - squashing commits together and rewording commit messages as required.
I've personally found this to be easier to use than git stash
, as I typically find I lose track of what stashes are meant to be about. (My fault rather than a flaw in git, but the effect is still bad.) I suspect that git reset
would be fine too, but as I often have to rebase anyway before a final merge - e.g. to react to code review comments - I have git rebase
as a more mentally efficient part of my workflow.
See more on this question at Stackoverflow