Git CLI is a powerful version control tool that allows developers to track code changes through commits. This enables developers to review their progress, revert to previous states, and make edits at any point in time.
Before pushing or updating the source code, developers often make multiple commits, sometimes more than 10 or fewer depending on the complexity of the changes. To keep the commit history clean and manageable, Git offers a feature called git squash. This feature allows developers to combine multiple commits into a single, cohesive commit. Squashing commits is especially useful when preparing to merge branches, as it simplifies the commit history and helps focus on the significant changes made, rather than cluttering the log with minor adjustments or fixes.
As shown in the image above, the squashed commit in the HEAD, labeled Clean up code, includes several sub-commits. This makes tracking changes more straightforward. With this squashed commit, even if you’re refactoring a large portion of the code, you can still look at the sub-commits within the squashed commit. If the application behaves unexpectedly after refactoring, you can easily inspect individual sub-commits and revert specific changes, ensuring better control and traceability over the development process.
The Different between commit each and squash
In conclusion, using git squash
not only keeps the commit history tidy but also allows developers to manage and revert complex changes efficiently, making it an essential practice in collaborative development environments.
Top comments (0)