Taking Control of Your Git History:Editing History
Published on Parts of this series:
Much like human history, Git history doesn’t necessarily reflect exactly what happened, but unlike human history, it shouldn’t have to.
We might want to do that if we want to amend some commits with additional changes, edit their commit message, exclude them from the branch etc. Once we get comfortable with doing this, our commits are no longer final; we can tweak them as much as we want until their diffs and commit messages are just right and they are ready to be reviewed and (hopefully) merged. People viewing our commits shouldn’t have to go through of every aspect of our process, e.g. that we later remembered to add tests, or that we decided to revert a change. Instead, let’s make it concise and descriptive for them.
However, just because we can change history doesn’t mean we always should. Specifically, we shouldn’t change history on branches that multiple people are working on. If we change history of the upstream branch with git push --force
, then everyone else who also works on that branch has to have that same history locally, but if they already committed some changes, it can get really messy, so don’t do that. 😉
This part of the series is a collection of various instructions to help you create the Git history you want.
What about squashing?
When we’re working on our task, it rarely happens that we know exactly what changes we’re going to make. Sometimes it happens that in order to do our task, we need to do something else first. It’s easy to push a bunch of commits like this to our branch:
- “handle empty arrays in
extractWorkers
” - “fix config”
- “fix tests”