Commit guidelines

Everything about development and the OpenMW source code.
Post Reply
blunted2night
Posts: 63
Joined: 28 Dec 2012, 08:29

Commit guidelines

Post by blunted2night »

Hi all,

I would like to have a discussion about potentially establishing some guidelines for commits submitted via pull requests. I will start by describing my workflow and a common pattern that concerns me, I will then make some recommendations that I believe will produces an easier to follow commit history. I chose the word guidelines because I believe they need to be just that. If they where hard rules, I think they would interfere with 'getting things done'.

I believe that the commit history should be less about the specific order in which the changes where made, and more about being a series of logical evolutionary steps that the code has gone though. Counter to that ideal, I find that my development processes is somewhat chaotic, in as much as I start on a piece of code, then move on to the next, then often have to go back and fix or extend an existing piece of code before proceeding. In an effort to bring order to the chaos, I try to take the approach of making lots of little independent commits, then reordering and combining those commits into a coherent series commits that make the evolution easily apparent.

Merging master into a feature branch can make it difficult to see changes made to resolve conflicts as you have to pick out the fixes from the merge. This is particularly problematic for non-trivial conflicts. It also has the potential to change the identity of master if the request is subsequently pulled instead of merged into master. In this case, master appears to be a feature branch will all kinds of other pulls/merges and the original feature branch looks like master. In the following image, the highlighted commits show points where master was merged into a feature branch that was then pulled into master making it difficult to follow the main line of development as it jumps around. In this image, master starts, at the bottom, as the green line, then is merged into the red line before finally being merged into the black line.
history-problem-1.jpg
history-problem-1.jpg (7.34 KiB) Viewed 3664 times
I recommend the following guidelines for submitted pull requests:
  • Avoid merging master into feature branches, if changes from master are required, re-base the feature branch onto master.
  • Whenever possible, pull requests should be re-based against master prior to being submitted.
  • If continuing development on a feature branch that has been merged into master, pull the merge commit into the feature branch so the the feature branch now diverges from master at that point instead of when the feature branch was originally created.
  • If shared development is required off master, then create a separate branch to represent that shared development, and treat it as a master branch.
User avatar
pvdk
Posts: 528
Joined: 12 Aug 2011, 16:34

Re: Commit guidelines

Post by pvdk »

Thanks blunted2night, I didn't know half of this stuff :oops:
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Commit guidelines

Post by sirherrbatka »

any idea where it should go on the wiki?
blunted2night
Posts: 63
Joined: 28 Dec 2012, 08:29

Re: Commit guidelines

Post by blunted2night »

sirherrbatka wrote:any idea where it should go on the wiki?
It could be an amendment to the Branching Policy page.
corristo
Posts: 495
Joined: 12 Aug 2011, 08:29

Re: Commit guidelines

Post by corristo »

Whenever possible, pull requests should be re-based against master prior to being submitted.
So after feature merge we will get linear history without explicit merge commit? I don't think it's the way to go, a successful git branch model called git-flow always merges features explicitly, even when fast-forward is possible. And I think this makes sense.

Also rebasing could be a problem if someone already forked your feature branch before you rebase and made couple of changes.
blunted2night
Posts: 63
Joined: 28 Dec 2012, 08:29

Re: Commit guidelines

Post by blunted2night »

corristo wrote:
Whenever possible, pull requests should be re-based against master prior to being submitted.
So after feature merge we will get linear history without explicit merge commit? I don't think it's the way to go, a successful git branch model called git-flow always merges features explicitly, even when fast-forward is possible. And I think this makes sense.

Also rebasing could be a problem if someone already forked your feature branch before you rebase and made couple of changes.
Rebasing can be problematic when others base changes on your branch, but in most cases that does't happen. Patches are easier to review when they are relative to the latest master, and don't have changes hidden in merges from master. So whether or not a fast forward merge is used to bring a pull request into master or not, having it rebased against master is still valuable.
User avatar
psi29a
Posts: 5361
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: Commit guidelines

Post by psi29a »

Thank you for taking the time to write this, it is extremely helpful. I come from the mercurial world, so git was a slight shift for me. ;)

Question though, how would you treat small bug-fixes? Is that branch-worthy or can I just push to master (or next) as the case my be?

Define "small": one file modified, only a few lines with no impact outside of the file. No new functionality.
blunted2night
Posts: 63
Joined: 28 Dec 2012, 08:29

Re: Commit guidelines

Post by blunted2night »

BrotherBrick wrote:Thank you for taking the time to write this, it is extremely helpful. I come from the mercurial world, so git was a slight shift for me. ;)

Question though, how would you treat small bug-fixes? Is that branch-worthy or can I just push to master (or next) as the case my be?

Define "small": one file modified, only a few lines with no impact outside of the file. No new functionality.
For me all changes are done on a branch because they are so cheap. For this project, that will always be the case as we all have to get Zini to merge our pull requests. Since joining this project, I have converted my primary project at work from bazaar to git, and I always work on a branch on a private repository. I like git because branches are so lightweight, just a pointer to a specific commit.
Post Reply