DEV Community

Up your git game with --patch

jess unrein on October 22, 2018

We all strive for clean, single purpose commits with meaningful messages. This can be difficult in practice if you’ve done a lot of debugging since...
Collapse
 
biros profile image
Boris Jamot ✊ /

Thanks for that !
Git is really powerful.
But I wonder who really needs this feature.
If you want clean commits, you better change things one by one. First the typo, then the others.
I can't imagine using this frequently. It would waste a lot of time.
But it's my opinion.
Thanks again for your post!

Collapse
 
thejessleigh profile image
jess unrein

That's so interesting! For me, waiting until you've completely finished one thought to start working on something else feels like it would be more time consuming, basically turning each individual thought process into a blocking task. Separating out the changes into clean commits after my ideas have come together makes way more sense for the way my brain works.

I guess it just goes to show that people's brains work in wildly different ways!

Collapse
 
biros profile image
Boris Jamot ✊ /

Maybe that's because I don't (always) do clean commits 😌
Sometime, I'm in the middle of an atomic commit and I come across a typo of my colleague. I better correct it now because I won't open a ticket for that and if I don't do it now, I'll forget it.
If I'm lucky it's in a separate file and I can skip it in the commit, otherwise...
How do we call that ? Laziness ? ☺️

Collapse
 
darksmile92 profile image
Robin Kretzschmar

I also never heard of the patch command, thanks for that!
Really needed this to cleaner commits.

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

You changed (destroyed) functionality in first hunk - you deleted role parameter and you left assignment into role attribute.

Collapse
 
thejessleigh profile image
jess unrein

Article has been updated to reflect this, and I added a bit about popping into your terminal's default editor to manually stage changes for commit. Thanks again for the catch!

Collapse
 
thejessleigh profile image
jess unrein

Oh, that was an oversight on my part. Thanks for catching that. I will fix that in a bit!

Collapse
 
vlasales profile image
Vlastimil Pospichal

Thanks for your article!

Collapse
 
0xyasser profile image
Yasser A

I never heard of that, nice!

Collapse
 
mnorbi profile image
Norbert Madarasz

Did you try creating animated gif(s) from the above steps?
It might be easier to follow.

Collapse
 
thejessleigh profile image
jess unrein

I haven't. I actually have never made an animated gif, but that's something worth looking into, for sure!

Collapse
 
biros profile image
Boris Jamot ✊ /

Have a look at ttyrec/ttygif !

Collapse
 
jsrn profile image
James

Nice post! I've been doing this for ages using the GitHub Desktop interface, but I'd never learned to do it with the CLI.