Loading
Back to all posts

Patch your git

First off, if you’re a developer and you’re not using version control, get yourself onto git and GitHub right now! There are lots of great tutorials to get you started with the basics.
And if you are already using git, well… congratulations!
Developing new projects and features can be really engaging. It’s easy to get lost in what you’re building, to lose track of time and forget to commit. Everyone does it. When you finally get around to committing and you have 15 or more files containing a mixture of unrelated changes, what do you do? If we are honest, most of us just commit a few changes at a time in the smallest segments as we can, right?
Well, no more! Enter the git add -p feature.
The -p or --patch option on git add will take you to an interactive tool that will split your files and changes into “hunks” or segments of code to be staged (added) separately. This will allow you to stage parts of any file relating to a single change, while keeping the other changes, but without staging them for commit. Once all the parts to a change are staged, you can commit as usual and repeat the process for the next change, maintaining a nice commit history and a sensible version history.
That means a happier ‘future you’ when you have to revert a change later on!