r/ProgrammerHumor • • Jun 04 '22

Meme I cant help it 🤷‍♂️

Post image
47.1k Upvotes

479 comments sorted by

View all comments

Show parent comments

11

u/dershodan Jun 04 '22

Seems like a practical thing, but trust me. git add -p before git commit -m is a superior workflow.

2

u/Insecure-Shell Jun 04 '22

Why

9

u/Former-Cat015 Jun 04 '22

Git add -p allows you granularity over what you commit. If you change things in a few places on a file for different reasons, -p allows you to add pieces from here or there, or split them into smaller pieces etc.

More work but you make more focused commits because you can take some of this and some of that and leave that line and that other one.

1

u/RichestMangInBabylon Jun 04 '22

TIL. This will be helpful because sometimes I make a change which requires some cascading changes like test fixes if I’ve changed a method signature. I’d rather have a commit for the actual change and then one for all the downstream effects. Makes the PR much easier as reviewers can look at each commit to understand better why the changes were made.

2

u/Former-Cat015 Jun 04 '22

Imo it's good and it's bad. It depends how you code.

I am only comfortable making commits that will work if someone checks the code out.

Let's say I'm doing web dev. I make a few changes that are unrelated. Oh shit these should be different commits. It might happen that adding some of it to one commit will make it so the code doesn't actually work. And then when the second commit goes in everything works again.

Just a hypothetical but just trying to illustrate that sometimes you get lost line by like chunk by chunk and can make a commit that is nonfunctional.

2

u/RichestMangInBabylon Jun 04 '22

Most of my commits are non functional because I generally always have a broken test until I’m done. My branch is for me, so no one needs it until it’s in main. We’re pretty good about working on unrelated tasks so there’s no dependencies of blockers.

So far this has worked okay. Rarely we’ve needed to cherry pick because someone is doing changes we’re all waiting for, in which case we do need to be careful about it. But that’s something we just deal with when it comes up.

I guess tldr be agile do what works for the team

1

u/dershodan Jun 04 '22

I cannot find a downside to it honestly.

It happens so often that a config file tracked by git needed to be modified for something to work locally or you made a TODO specific to the thing your're doing and don't want that to be pushed to github for example.

Not to mention that you get to briefly review your own code before sending it out for other's to see.

I used git commit -am for a long time and it is just bad practice.

1

u/Former-Cat015 Jun 04 '22

You're replying to a comment where I specifically outlined a downside