DEV Community

Fran C.
Fran C.

Posted on • Updated on

My small hook and my flow with git

I've just made this small git hook https://github.com/franciscoj/dot-files/blob/0825d35076ce4550db20a12ea54d73bf3d6cea63/git/hooks/commit-msg and I'm super happy because I've needed it for a long time!

It analyses the commit msg and adds a + sign at the beginning of the first line if the commit has more than 1 line. That way I can recognise commits with extended information.
git log with this change

When I'm coding serious stuff (like at work) I make very little and very atomic commits incrementally and I always try to keep things "green" and stable. When I say very little I really mean it. Sometimes those are things like "extract a variable" or "move this to the constructor" or "add an unused parameter".

I don't always to that as I make the change. Instead I play around a bit until I get where I want to and then I just commit small hunks little by little.

As I work on the task I extract things that are independent and can be rolled out on their own. Maybe a refactor that makes the new feature possible or a set of classes that aren't used yet but will be used by the new code I'm writing.

This way I also make sure that, on long projects, I keep sharing my code with my team as much as possible and gathering their continuous feedback.

I do that with many interactive rebases: editing, sqashing, splitting and reordering commits. I can't always do that, of course, but I try to code and commit taking that into account so that it is possible.

I normally extract stuff from my PR that can be independently rolled out and that can ease having a big feature in production without needing big last day deploys.

This way I start using the new code and capturing metrics about it before the new feature is even active for the final users, minimising the risk of performance or functional regressions.

PS: This started as a tweet explaining my silly hook and it went out of hand xD

Edit 2020 - 11 - 24: Updated the link to the hook to the latest version with some fixes I've done in the last weeks :)

Top comments (3)

Collapse
 
dmahely profile image
Doaa Mahely

I don't always to that as I make the change. Instead I play around a bit until I get where I want to and then I just commit small hunks little by little.

I do this as well. Sometimes I like to focus first on making the code work then I go over it and stage related changes bit by bit using VS Code's GUI.

Collapse
 
nflamel profile image
Fran C.

I do it with Vim's fugitive plugin. It has an interface that allows you to stage hunks pretty easily line by line.

Collapse
 
mrdarkside profile image
Tomi Tomion

I have small hook too