In this video you will learn how to, and why you may want or need to squash your git commits.
Simply put, squashing commits is the way of combining multiple commits into one commit.
Why might you want to do this?
The main reason is that one large commit is easier to process for the person reviewing your commits.
Another reason is that as you work on the bug, feature, or change on your local machine, you may well commit many small changes over time by way of giving yourself 'save points'. Particularly on larger projects / open source projects, the project commit logs can get very large and these small commits can create a lot of noise.
Instead, we can take two or more of our commits and squash them together into one single consolidated commit. We can give this new commit a more accurate / descriptive message to describe the purpose of the entire change as opposed to having to read all the individual messages and try to piece them together to form a cohesive view of the change.
Do not follow through with this procedure if you have already pushed your changes to a remote repository.
That's not to say you cannot use this technique moving forwards, but if - as an example - you have pushed up five commits to Github or Bitbucket or wherever, do not then squash these commits and re-push. This will cause all kinds of chaos.
If you want to follow along, and you would like the
.gitignore file as shown in the video, you can find that here.
Secondly, if you're wondering how to use the short hand for git, check out ohmyzsh.
The commands you will see in this video are:
That one should be pretty self explanatory :)
This is shorthand for adding all your new and modified files (excluding deleted files) to the git staging area.
gc -am "message"
This is shorthand for `git commit -a -m "message".
This is shorthand for
For seeing the current git log status.
git rebase -i HEAD~3
This is where the magic happens :)
In this command we are starting our rebase in interactive mode (
-i). We are saying go back 3 commits (
~3) from the HEAD (the current position).
From here it's a case of choosing which commits will be included in our squash, saving the selection, and then letting Git do its thing. After that, we are good to push.
If you have found this video helpful, please consider sharing. I really appreciate it.
|1||Squashing Commits Video Tutorial||05:51|
|2||Git Push Deploy||08:35|
|3||Patching with Git (git add -p)||02:53|
|4||Selectively Removing Parts of a Commit (git reset -p)||05:19|
|5||Making the most out of Git Log||06:20|
|6||Git Ignore Woes||04:51|