News for hackers. Stuff that matters.
Re:Write good git commit messages by gdfasfklshg4 on Wednesday December 12, 2018 @09:05AM (#18663955)
> This is also the primary reason why I highly dislike merge commits: They make git logs extremely unreadable.

I really really disagree. If the branch has one logical commit then no merge commit is needed. Otherwise the merge commit shows what happened and more importantly that these N commits came into the mainline as a single change.

Re:Write good git commit messages by scrollaway on Wednesday December 12, 2018 @09:25AM (#18664105)
So tell me, this is readable for you?

https://imgur.com/GCWsFwU

And I'm not cherry-picking... I usually see much, much worse git logs than this from merge-commit users. In fact, if I scroll down, this is what it looks like:

https://imgur.com/a/nQXWa4Q

Edit: For a point of comparison, here's one of my projects using atomic commits and rebases:

https://imgur.com/a/vTZ5qxT

Re:Write good git commit messages by gdfasfklshg4 on Wednesday December 12, 2018 @10:33AM (#18664718)
The first example does not rebase first...

My projects also have a linear progression. They look like...

    *     -- Bugfix
    *     -- Feature B
    | \
    | *   -- Implement some other logical part of feature B
    | *   -- Implement first logical part feature B
    | /
    *     -- Feature A
Re:Write good git commit messages by MayeulC on Wednesday December 12, 2018 @04:38PM (#18667979)
I am curious as to why this is downvoted? This can be a valid answer to the parent's concern.
Re:Write good git commit messages by monsieurbanana on Wednesday December 12, 2018 @09:33AM (#18664177)
Let me fix this for you...

git log --first-parent

With that switch and writing correct merge-commit messages you get the best of both approaches.

Re:Write good git commit messages by scrollaway on Wednesday December 12, 2018 @09:35AM (#18664195)
"And correct merge-commit messages" -- I've NEVER seen those. In 99.99999% of projects, this is what you'll get:

https://imgur.com/a/4f6Hw2w

Re:Write good git commit messages by monsieurbanana on Wednesday December 12, 2018 @09:42AM (#18664269)
You're moving goalposts. Yes almost nobody changes the default merge-commit message. But that's because, like you, they don't know about --first-parent (or they just don't care about commit history)

That doesn't mean using merge-commits is wrong, that means people write bad commit messages, which you already complained about.

Re:Write good git commit messages by scrollaway on Wednesday December 12, 2018 @09:49AM (#18664336)
… am I moving goalposts? I do know about --first-parent and it is not intended to be a feature to make git logs readable. It gets rid of nearly the entire git history. At this point, you might as well simply go to the github page and look at merged PRs; that will actually get you something readable.

I fear you may be terribly misunderstanding the point of atomic commits and readable commit messages. Everything within a merge commit will still come up during a bisect, for example. If the commits are non-atomic and/or they are badly written, that is still an issue.

--first-parent hides the problem, and adds a new one. I'm not sure what your thinking is. Once again, what's more readable to you of all the screenshots I linked?

Re:Write good git commit messages by btschaegg on Wednesday December 12, 2018 @03:45PM (#18667593)
Not to argue in either direction, but I think you should be able to "fix" the bisect problem with a script like this:

  #!/bin/bash
  bad=$(git rev-parse "$1")
  good=$(git rev-parse "${@:2}")
  
  git bisect start "$bad" $good
  
  filter=$(echo "$good" | sed 's/^/^/' | cat <(echo "$bad") - | xargs)
  comm -13 \
      <(git rev-list --first-parent $filter | sort) \
      <(git rev-list                $filter | sort) \
      | xargs git bisect skip
I haven't tested it all too thoroughly, but from what `git bisect view` tells me, this seems to work like a `git bisect --first-parent`. I'm wondering why there is no such option...

For anyone unfamiliar with git extension scripts: You should be able to put it in an executable (`chmod +x`) file (say `git-bisect-branch`) in your $PATH to make it usable (`git bisect-branch $bad $good...`).

Re:Write good git commit messages by gdfasfklshg4 on Thursday December 13, 2018 @06:08AM (#18671423)
Good branch names end up in the default commit by default...
Re:Write good git commit messages by mkesper on Wednesday December 12, 2018 @12:19PM (#18665699)
You'd want to use a repo that only allows fast-forward and rebase everything that would be a merge. We use Gerrit for that.
Re:Write good git commit messages by scrollaway on Wednesday December 12, 2018 @12:36PM (#18665864)
Yup, that's what I'm arguing in favour of. I systematically disable merge commits on every repo I manage.

I suspect that if merge-commits hadnt been the default on github since forever, it wouldnt have so many proponents.

Re:Write good git commit messages by gdfasfklshg4 on Thursday December 13, 2018 @05:10AM (#18671194)
> I systematically disable merge commits on every repo I manage.

Do you have buy in from other team members for this?

Also what do you do if master needs to be merged back into develop? Do you really rebase develop and make everyone fiddle with all their feature branches?

Re:Write good git commit messages by scrollaway on Thursday December 13, 2018 @10:05AM (#18672754)
There is no develop, master is continuously deployed. Users can create feature branches and PR them but there is just no merge commit, they are pulled in fast-forward. In projects where I need stable releases, I create stable/1.2.x type branches off of master at a point in time. I cherry-pick commits onto it after the first release if there are subsequent ones.

You can see this in action here:

https://github.com/dj-stripe/dj-stripe/commits/master

https://github.com/dj-stripe/dj-stripe/commits/stable/1.2

Re:Write good git commit messages by u801e on Thursday December 13, 2018 @02:36PM (#18675265)
Though fast forward merge commits (where the referenced tree is the same as referenced by the second parent) can be useful because they provide a way for you to group related commits for a feature together (git log merge_commit^..merge_commit^2). There are features that require more than a single commit to implement.
Re:Write good git commit messages by vsl on Thursday December 13, 2018 @08:45AM (#18672238)
Let me this fix for you too: don’t merge master into featur branches. What kind of insanity is that?
Re:Write good git commit messages by lysp on Wednesday December 12, 2018 @07:37PM (#18668948)
I go one step further - All changes (even single commits) are in a feature branch.

Feature branch is prefixed with issue number. eg. PROJ-1234-update-ui-to-do-something. That ensures that every commit is logged against an issue.

If you list --first-parent and show the list of merge commits, you see a list of features which were implemented into the dev branch.

If you need to drill down into lower level changes of a feature, you can look at the individual commits that were made in that branch.

That way merge commits are atomic commits of features, and commits in a branch are logical commits/steps for an individual feature.

And in answer to the original post - I try to make all commits have a message of what was the type of change, what the change was, and where it was. eg. "Added a clear button to reset all form elements on the update address page". The general rule is, you should be able to read the commit message and know exactly what was changed and where. Compared to "Added clear button".

Re:Write good git commit messages by maelkum on Friday December 14, 2018 @08:28AM (#18680623)
I am using this method to a great success at my current job. It leads to always having a clear, well-defined place where you look for changes related to issue XYZ.

Support from tooling also helps a lot, e.g. "checkout branch of issue XYZ".

Re:Write good git commit messages by scrollaway on Thursday December 13, 2018 @02:40AM (#18670529)
This is IMO a potentially good system but it requires a lot of rigor. In my experience, such systems break down unless they are rigidly enforced, and that's never fun for anybody.
Re:Write good git commit messages by lysp on Sunday December 16, 2018 @01:16AM (#18691992)
The way I have set it up is to do 2 things:

1) Create a post-commit hook script that only allows commits into feature branches.

This prevents accidentally committing into the dev/master branches (it still allows merges).

2) Create a script file that all developers use to start / end features which handles all the branch creation, pushing and pulling. That way the process is standardised and you cant make a mistake.

eg.

* script startfeature abc123-this-is-new-feature

* script endfeature (this automatically picks up local open features)

The only time there is ever an issue is when the end-feature causes a conflict. This is solved by rebasing your local branch, fixing up any issues in your commmits and then ending it again.

Re:Write good git commit messages by adtac on Wednesday December 12, 2018 @09:20AM (#18664056)
I fail to see how that would be useful. Commits are supposed to be atomic, self-contained changes by themselves. More often than not, I see merge commits only when people abuse commits for temporary state of work (with useless commit messages like "fix" and "temp"). Instead, if each commit did one thing and one thing only, why would you need a visual indicator that these set of commits came from a particular branch?
Re:Write good git commit messages by jonahx on Wednesday December 12, 2018 @09:52AM (#18664358)
Because they are logically grouped and that grouping is often more important than the commits themselves -- together, they accomplish a higher-level goal.

You want both that goal and the individual tasks which achieved it to be visible.

Re:Write good git commit messages by adtac on Wednesday December 12, 2018 @09:56AM (#18664400)
That information can and should be a part of the commit body. An extra commit just for that information is, in my opinion, a hack and a workaround.

I guess we have fundamental differences on how a tree should be structured. It's more of a DAG in your case, but I prefer to keep a tree a tree.

Re:Write good git commit messages by jonahx on Wednesday December 12, 2018 @11:27AM (#18665214)
Not sure I follow your argument. How would you put information about the semantic meaning of a series of commits into "the commit body"?

The only point I'm making essentially is that "the commit" is too granular to capture all the information you need about your work and its history. You need some kind of grouping mechanism as well. It doesn't have to be merge commits, necessarily. But as I understood it, your original argument was that "there is no need for anything higher level than a commit." But there clearly is imo.

Re:Write good git commit messages by Thiez on Wednesday December 12, 2018 @01:51PM (#18666611)
If you tag HEAD after each merged PR you can still see which commits belong together, they'll be between two tags.
Re:Write good git commit messages by jonahx on Wednesday December 12, 2018 @02:36PM (#18667022)
Yeah, when I said:

> It doesn't have to be merge commits, necessarily.

I was thinking of a tagging strategy.