git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 0/1] *** Add branchname in commit header ***

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Dec 30, 2019, 02:32 UTC
Message-ID
<20191230023250.GC6570@camp.crustytoothpaste.net>
In-Reply-To
<20191229222633.23815-1-arnaud.bertrand@abalgo.com>
On 2019-12-29 at 22:26:32, Arnaud Bertrand wrote:
Show 14 quoted lines
> From: Arnaud Bertrand <xda@abalgo.com>
> 
> For tracability purpose it is often necessary to know which
> commit is envolved in a branch
> Keeping track of the branchname in the commit header
> will make this traceability easy and will facilitate
> the graphical toolis that represent the branches and
> that have today to use complex algorithm to try to
> determine the branch of a commit that was known at
> the commit time.
> 
> no big change in the code, today rebase is not considered yet
> I'm waiting feedback about that before touching
> the rebase code.

I encourage you to read back in the history of the list as to why we haven't done this and why it's not likely to be accepted now, but let me provide a few reasons of my own.

First, as any contributor to the mailing list can tell you, I am absolutely terrible at naming things. I frequently name my branches something that makes sense to me at the time without regard to whether that will make sense in the future. I don't want to memorialize my momentary thoughtlessness in the history of the repository forever.

Second, one workflow I commonly use is creating a branch with many commits and then breaking them down into small series that are logical and easy for review. If I have a branch called "test-fixes-part7" with 50 commits and then I decide to split that into two branches, test-fixes-part7 and test-fixes-part8, by copying the branch and using git reset --hard to truncate the old one, I don't want the old branch name in my new branch. A lot of Git workflows assume you can reset and rename branches this way and having the branch name in the commit header breaks those workflows.

Third, people reuse branch names. Right now, I have eight branches with test fixes all starting with "test-fixes-part" because I'm working on one major project with all of those test fixes. However, if a developer working on another major project also has a lot of changes to the test suite, they may have lots of identically named branches, which would be confusing, since our identically named test fix branches would relate to different projects. (See my first point.)

However, despite the fact that we aren't likely to add this in the commit header, there are definitely ways to achieve this.

If you want to include the branch name in the commit, you can do so with a trailer. git interpret-trailers can then be used to manipulate and extract these, and along with a hook, add them automatically if they're missing.

If you're working on a more centralized project and you want to require the branch name in your commit trailers, you can set your CI system to fail or reject commits that don't contain them. This is the approach that systems like Gerrit use when the required trailers are missing and it seems to work reasonably well.

Hopefully these suggestions are helpful in getting you the traceability you desire without requiring fundamental changes to the way Git works.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Arnaud BertrandNext: Arnaud Bertrand
Message 3 of 7 in “*** Add branchname in commit header ***”
  1. 0/1 *** Add branchname in commit header ***Arnaud Bertrand, Dec 29, 2019
  2. 1/1 Add branchname in commit headerArnaud Bertrand, Dec 29, 2019
  3. brian m. carlsonDec 30, 2019
  4. Arnaud BertrandDec 30, 2019
  5. 0/2 *** Add branchname in commit when core.branchnameincommit is set ***Arnaud Bertrand, Dec 30, 2019
  6. 1/2 Add branchname in commit headerArnaud Bertrand, Dec 30, 2019
  7. 2/2 Add the configuration parameter core.branchnameincommitArnaud Bertrand, Dec 30, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.