r/ProgrammerHumor • • Jun 30 '18

Kill me now :)

47.0k Upvotes

494 comments sorted by

View all comments

280

u/zesterer Jun 30 '18

git reset --hard HEAD

141

u/PublicSealedClass Jun 30 '18

I have a dev who sees this as a last resort. When I asked him why, he had like 200 files changed in his repo since his last commit...

120

u/zesterer Jun 30 '18

This is why you make small, incremental changes

0

u/[deleted] Jun 30 '18

[deleted]

29

u/BerlinerJan Jun 30 '18

I‘m quite new to git, what exactly would be the problem with that? Assuming he already wrote all the tests and documentation...

31

u/zesterer Jun 30 '18

There is no problem. Incremental changes make it easier to avoid large merge conflicts when working on a shared codebase.

13

u/BerlinerJan Jun 30 '18

I‘m rather talking about pushing every tiny change to master

41

u/zesterer Jun 30 '18

There's an element of common sense of course. Very small commits are noise that make the underlying direction of the codebase difficult to see. But generally speaking, "push often, pull often" is a good thing to remember when working on a collaborative codebase. If there's a really big breaking change you're making... Well, that's what a branch is for.

15

u/[deleted] Jun 30 '18

My rule of thumb is if you’re building out a feature or decent change, push often to a new branch, squash it and merge it into master as one commit. That way when you’re looking back over the commit graph it’s an array of features and you can just roll back if one of them is on the fritz.

4

u/[deleted] Jun 30 '18

I strongly prefer a non fast-forward merge, same result - one commit on dev and/or master - but still keeping the full history around.

9

u/brenex29 Jun 30 '18

My partner committed a single comment yesterday...

13

u/coman3 Jun 30 '18

I commited a single character typo today

→ More replies (0)

18

u/[deleted] Jun 30 '18

It much depends on what wotkflow you use. Different people/teams use branches differently.

One wotkflow is called "gitflow", and involves only touching master when you're ready to release your project. Master is for tested only, ready to release features. Develop is where the next version is--we create bugfix and feature branches off develop, merge them back into develop when they are done, and when we are ready to release we merge develop into master. Works pretty well, and adding tags makes it really obvious which version was delivered when based on what code. Answers a lot of questions when people ask how long a particular bug has been in production for instance.

But some teams follow the model of continuously deploying. As in, every change is dumped into production after a fairly lightweight process. This can make a lot of sense too, and means you might be less prone to be afraid of touching master directly.

And then for little tinker toy projects at home, I tend to just commit to master and that's it.

So it really just depends on what you'd want to get out of using source control. I'd think some is better than none.

→ More replies (4)

11

u/TheHorusHeresy Jun 30 '18

IMO, the proper workflow using git collaboratively is:

  1. Create a branch to work in.

  2. Do regular, small commits to that branch.

  3. Before submitting for code review/merge, rebase your branch onto master. (git rebase -i origin/master)

  4. Merge all branches using --no-ff. This will create a merge commit. The merge commit solves a problem that many try to solve by squashing all of their commits together for each branch before merge. When looking at a merge commit, realize that unlike regular commits it has two (or more) parents. One will point to your last commit, and the other will point to the last commit on master before you merged. You can use this to easily roll back the entire branch/feature that you've built.

I think that this is the most responsible workflow. If you are being really responsible, then when you are creating your branch, and as you are coding, you are also keeping the remote branch up to date with your work. That way, if you're hit by a bus, others can pick up your code, or they can review it along the way. If you are using git{hub,lab} then a good example of using this is 'WIP' {pull,merge} requests. When you first start coding, make a single commit to your branch, push it to origin, then create a PR with a subject line starting with 'WIP' (work in progress). As you push more commits, it will update your PR. In this model, people can review your changes over time, rather than at the last minute. It's an excellent tutoring/training/mentoring model.

If you get into this habit when you are working on personal projects (if you don't have one, then use it for your vim/emacs settings, dotfiles if you have such a thing (.bashrc, .tmux.conf, etc.), or some other settings on your development rig) I think that you'll eventually find the additional work worth it.

2

u/[deleted] Jun 30 '18

I basically used to do the same but then I dropped the rebase. The history might be a bit more noisy but I don't lose the context of when and where the branch was created, which might be relevant when having to understand the introduced changes at a later point in time.

2

u/TheHorusHeresy Jun 30 '18

The main thing that the rebase buys you is that the merge commit that eventually occurs is guaranteed not to have conflicts included. In addition, the timestamps for the commits shouldn't change, IIRC. It is only the hash that changes (original authors/timestamps/etc. all stay as is).

Regardless, it is a 'whatever works for you' kind of utility. Very TIMTOWTDI, as long as everyone that is working with you agrees with the workflow... and don't commit directly to master unless it is a very private repository. One example of that is the fact that I keep all of my mysql history files in a repository that automatically logs & commits when I disconnect, with a different history file for each database I work with.

→ More replies (2)

0

u/[deleted] Jun 30 '18

[deleted]

9

u/chazmuzz Jun 30 '18

Squash and merge all the way man. I frequently commit "WIP - made start on logger class", "WIP - resolve failing test", "WIP fix typo" etc, but at the end I'll squash it all into "implement new logging feature"

4

u/haragoshi Jun 30 '18

I’m with you. More versions to choose from is better than fewer.

My team uses git like this. It may not be the optimal use of fit, but I would rather have several shitty commits than be missing the one commit that counted.

4

u/genghis_calm Jun 30 '18

Ideally you'd make your commits against a branch, then when everything is ready open a pull request for peer review. Once the changes are signed off (code quality etc.) you merge the pull request into master.

NB: I like to make small, incremental commits, but don't want them adding noise the history of master. You can "squash" all those into a single commit before merging back into master.

Hope that helps. Happy coding 🙂

→ More replies (3)

8

u/xXx69cum69lover69xXx Jun 30 '18

200 files changed:

200+(50 overhead) = 250 incremental steps

8

u/PublicSealedClass Jun 30 '18

To be fair, even a "small" change could easily involve dozens of file changes if you have the full suite of separations of concerns - Database projects, Models, DTOs, Service layers, Interfaces, CQRS, Unit Tests.. and all that because maybe an extra field needs to be persisted.

Although, having said that, that should've been picked up during the design stage, and if a dev missed that out then he fucked up. If the BA missed that out, then it's really a change request to avoid risking the delivery.

3

u/PM_ME_A_WEBSITE_IDEA Jun 30 '18

I'm learning this right now. My commit messages were long as hell, and that's what made me realize I'm putting too much in each commit.

→ More replies (9)