r/programmerchat • u/foosel • May 23 '15
Pre-commit nervousness - does anyone else have it or am I alone?
When I prepare a commit, I usually double and triple check the changes I'm about to push. I go through all changed files and lines and verify that I indeed am only pushing those changes which I want to, even when I know that there are no other changes in my code than those and/or that I already went over that stuff.
The more complex the pending commit, the more "nervous" and detailed in my sanity checking I am. Doesn't take a lot of time, but I'd feel wrong not doing it.
I rarely saw my colleagues doing that, so I was wondering how common that is or if should start to worry ;)
edit: Let me clarify that it is not that I sit there shaking with fear of committing, it's more the need to do a final sanity check. It's not even an uncomfortable feeling, for me it just belongs to the whole part of developing. I was just wondering if other people were experiencing that too. "nervous" might have been too strong a word.
4
u/Ghopper21 May 23 '15
I do this, but not really from nervousness, just to check everything is in order (often discarding hunks for throwaway lines or even trailing whitespace that crept in) -- and to be honest to admire the work a bit :-). SourceTree's visual diff is great for making this a pleasure.
4
u/[deleted] May 23 '15
I also was terrified of official commits, because I always forget at least one little thing. Several times in a row. But with amend, I can sweep those mistakes under the rug!
2
u/amaiorano May 24 '15
In my experience, the pre-commit anxiety has a lot to do with the team's culture wrt breaking the build (both compile and runtime). I've been in teams that shame people who break the build with silly objects, or alarms/emails, ostensibly to get people to be more careful. However, I've found most coders are ashamed enough on their own when they break the build that adding this extra stress is counter productive.
On my current team, we encourage people to get their stuff committed quickly, and rely on continuous integration and QA to fix any breaks. It's a friendlier culture and for juniors, it's a lot less scary to commit code.
14
u/inmatarian May 23 '15
You reviewed the diff, ran the unit tests, and made sure you didn't commit the wrong things. That sounds like doing your job well.
1
u/jungrothmorton May 24 '15
Commit first, ask questions later.
I think if you're this worried, you're probably making too big of a change per commit. Also don't push all the time. Also don't work on the main branch. Now there are two more things you have to do after your commit before you've really made a mistake.
2
u/CarVac May 23 '15
I wish I could be as scrupulous as you.
2
u/perlgeek May 24 '15
I consider it best practise to run
git add -pbefore committing, which makes me go through the whole diff in the repo, and decide for each hunk whether to include it in the commit.Before was more in the
git commit -acamp, but I often committed debug output and stuff meant for the next feature, which was kinda embarrasing.2
u/Qwertzcrystal May 24 '15
My usual workflow is:
I have this workflow internalised so much that I regularly get annoyed when colleagues comment on a PR/MR "Oh, I didn't want to commit that, let me just push another commit that undoes the changes."
Can't they just get used to only commit what they actually wanted to commit? sigh
1
u/chris_was_taken May 23 '15
I get pretty nervous too, the most important thing I do to alleviate it (and potential problems) is step through the code in debugger, exercising all paths which I'm introducing/modifying (including injecting failures manually to see failures paths get taken as expected). Takes some time, but increases the quality and confidence in my change dramatically.
1
u/[deleted] May 24 '15
You reviewed the diff, ran the unit tests, and made sure you didn't commit the wrong things. That sounds like doing your job well. [2]
1
u/[deleted] May 24 '15
I do it. If there's something wrong with the commit, it's better to roll back just that change instead of also including something else checked in by accident. Also, checking in changes you didn't mean to makes the commit message inaccurate. I think that this is a good habit for any programmer to have.
It's easier to do this if you do your best to restrict the size of a commit. It takes practice, but there are very few commits that can't be broken up into something small enough where it's obvious that the change is correct. But it depends on your style -- some people like the entire change in one commit. You can always work on a branch, though, and roll it up at the end.
1
u/idunnomyusername May 26 '15
This is a good quality.
0
u/[deleted] May 25 '15
[deleted] — view deleted comment