{"thread":{"id":"52536","subject":"[RFC PATCH 0/1] *** Add branchname in commit header ***","startedAt":"2019-12-29T22:27:16Z","lastAt":"2019-12-30T16:33:26Z","messageCount":7,"participants":["Arnaud Bertrand","brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"389045","messageId":"20191229222633.23815-1-arnaud.bertrand@abalgo.com","threadId":"52536","inReplyTo":null,"subject":"[RFC PATCH 0/1] *** Add branchname in commit header ***","fromName":"Arnaud Bertrand","fromEmail":"arnaud.bertrand@abalgo.com","sentAt":"2019-12-29T22:26:32Z","receivedAt":"2019-12-29T22:27:16Z","isPatch":true,"sender":{"key":"arnaud.bertrand@abalgo.com","avatar":null},"body":"From: Arnaud Bertrand <xda@abalgo.com>\n\nFor tracability purpose it is often necessary to know which\ncommit is envolved in a branch\nKeeping track of the branchname in the commit header\nwill make this traceability easy and will facilitate\nthe graphical toolis that represent the branches and\nthat have today to use complex algorithm to try to\ndetermine the branch of a commit that was known at\nthe commit time.\n\nno big change in the code, today rebase is not considered yet\nI'm waiting feedback about that before touching\nthe rebase code.\n\n\nArnaud Bertrand (1):\n  Add branchname in commit header\n\n Documentation/pretty-formats.txt |  1 +\n commit.c                         | 11 +++++++++++\n pretty.c                         | 15 +++++++++++++++\n 3 files changed, 27 insertions(+)\n\n-- \n2.25.0.rc0.7.g17b02bf28a\n\n"},{"id":"389046","messageId":"20191229222633.23815-2-arnaud.bertrand@abalgo.com","threadId":"52536","inReplyTo":"20191229222633.23815-1-arnaud.bertrand@abalgo.com","subject":"[RFC PATCH 1/1] Add branchname in commit header","fromName":"Arnaud Bertrand","fromEmail":"arnaud.bertrand@abalgo.com","sentAt":"2019-12-29T22:26:33Z","receivedAt":"2019-12-29T22:27:16Z","isPatch":true,"sender":{"key":"arnaud.bertrand@abalgo.com","avatar":null},"body":"From: Arnaud Bertrand <xda@abalgo.com>\n\nAdd the branchname in the commit header before the commit message\nthe following line is added:\n\nbranch <branchname>\n\nwhere <branchname> comes from the function resolve_ref_unsafe(\"HEAD\",...)\nwithout the prefix refs/heads/\nA placeholder is added to the pretty format \"%Xb\" to print the branch information,\nX if for \"extra-header\" and can be use in the future for new features\nb is of course for \"branch\"\n\nthe %Xb returns an empty string when branchname information is not found\n---\n Documentation/pretty-formats.txt |  1 +\n commit.c                         | 11 +++++++++++\n pretty.c                         | 15 +++++++++++++++\n 3 files changed, 27 insertions(+)\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex 1a7212ce5a..bd52908f53 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -241,6 +241,7 @@ endif::git-rev-list[]\n '%gE':: reflog identity email (respecting .mailmap, see\n \tlinkgit:git-shortlog[1] or linkgit:git-blame[1])\n '%gs':: reflog subject\n+'%Xb':: branchname in which commit was done\n '%(trailers[:options])':: display the trailers of the body as\n \t\t\t  interpreted by\n \t\t\t  linkgit:git-interpret-trailers[1]. The\ndiff --git a/commit.c b/commit.c\nindex 434ec030d6..f64a0698be 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1425,6 +1425,9 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \tint result;\n \tint encoding_is_utf8;\n \tstruct strbuf buffer;\n+\tconst char *branch = \"Unknown\";\n+\tint flags;\n+\tconst char *lbranch =resolve_ref_unsafe(\"HEAD\",0,NULL,&flags);\n \n \tassert_oid_type(tree, OBJ_TREE);\n \n@@ -1453,6 +1456,14 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \t\tauthor = git_author_info(IDENT_STRICT);\n \tstrbuf_addf(&buffer, \"author %s\\n\", author);\n \tstrbuf_addf(&buffer, \"committer %s\\n\", git_committer_info(IDENT_STRICT));\n+\tif (lbranch) {\n+\t   skip_prefix(lbranch,\"refs/heads/\",&branch);\n+\t   strbuf_addf(&buffer, \"branch %s\\n\", branch);\n+\t}\n+\telse {\n+\t   strbuf_addf(&buffer, \"branch Unknown\\n\");\n+\t}\n+\n \tif (!encoding_is_utf8)\n \t\tstrbuf_addf(&buffer, \"encoding %s\\n\", git_commit_encoding);\n \ndiff --git a/pretty.c b/pretty.c\nindex 305e903192..5961c39398 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -804,6 +804,7 @@ struct format_commit_context {\n \n \t/* The following ones are relative to the result struct strbuf. */\n \tsize_t wrap_start;\n+\tchar *branch;\n };\n \n static void parse_commit_header(struct format_commit_context *context)\n@@ -1367,6 +1368,20 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */\n \t\treturn 1;\n \t}\n \n+\n+\t/* Now add extra header info */\n+\tif (placeholder[0] == 'X') {\n+\t\tswitch (placeholder[1]) {\n+\t\tcase 'b': /* branch ... */\n+\t\t\tc->branch = get_header(msg,\"branch\");\n+\t\t\tif (c->branch)\n+\t\t\t\tstrbuf_addstr(sb, c->branch);\n+\t\t\tfree(c->branch);\n+\t\t\treturn 2;\n+\t\t}\n+\t}\n+\n+\n \t/* Now we need to parse the commit message. */\n \tif (!c->commit_message_parsed)\n \t\tparse_commit_message(c);\n-- \n2.25.0.rc0.7.g17b02bf28a\n\n"},{"id":"389054","messageId":"20191230023250.GC6570@camp.crustytoothpaste.net","threadId":"52536","inReplyTo":"20191229222633.23815-1-arnaud.bertrand@abalgo.com","subject":"Re: [RFC PATCH 0/1] *** Add branchname in commit header ***","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-12-30T02:32:50Z","receivedAt":"2019-12-30T02:32:56Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2019-12-29 at 22:26:32, Arnaud Bertrand wrote:\n> From: Arnaud Bertrand <xda@abalgo.com>\n> \n> For tracability purpose it is often necessary to know which\n> commit is envolved in a branch\n> Keeping track of the branchname in the commit header\n> will make this traceability easy and will facilitate\n> the graphical toolis that represent the branches and\n> that have today to use complex algorithm to try to\n> determine the branch of a commit that was known at\n> the commit time.\n> \n> no big change in the code, today rebase is not considered yet\n> I'm waiting feedback about that before touching\n> the rebase code.\n\nI encourage you to read back in the history of the list as to why we\nhaven't done this and why it's not likely to be accepted now, but let me\nprovide a few reasons of my own.\n\nFirst, as any contributor to the mailing list can tell you, I am\nabsolutely terrible at naming things.  I frequently name my branches\nsomething that makes sense to me at the time without regard to whether\nthat will make sense in the future.  I don't want to memorialize my\nmomentary thoughtlessness in the history of the repository forever.\n\nSecond, one workflow I commonly use is creating a branch with many\ncommits and then breaking them down into small series that are logical\nand easy for review.  If I have a branch called \"test-fixes-part7\" with\n50 commits and then I decide to split that into two branches,\ntest-fixes-part7 and test-fixes-part8, by copying the branch and using\ngit reset --hard to truncate the old one, I don't want the old branch\nname in my new branch.  A lot of Git workflows assume you can reset and\nrename branches this way and having the branch name in the commit header\nbreaks those workflows.\n\nThird, people reuse branch names.  Right now, I have eight branches with\ntest fixes all starting with \"test-fixes-part\" because I'm working on\none major project with all of those test fixes.  However, if a developer\nworking on another major project also has a lot of changes to the test\nsuite, they may have lots of identically named branches, which would be\nconfusing, since our identically named test fix branches would relate to\ndifferent projects.  (See my first point.)\n\nHowever, despite the fact that we aren't likely to add this in the\ncommit header, there are definitely ways to achieve this.\n\nIf you want to include the branch name in the commit, you can do so with\na trailer.  git interpret-trailers can then be used to manipulate and\nextract these, and along with a hook, add them automatically if they're\nmissing.\n\nIf you're working on a more centralized project and you want to require\nthe branch name in your commit trailers, you can set your CI system to\nfail or reject commits that don't contain them.  This is the approach\nthat systems like Gerrit use when the required trailers are missing and\nit seems to work reasonably well.\n\nHopefully these suggestions are helpful in getting you the traceability\nyou desire without requiring fundamental changes to the way Git works.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"389056","messageId":"CAEW0o+jxm+2vC2zhUtz8GgaZeYtXMt2LXgNk8kk7VhQX5Z4arA@mail.gmail.com","threadId":"52536","inReplyTo":"20191230023250.GC6570@camp.crustytoothpaste.net","subject":"Re: [RFC PATCH 0/1] *** Add branchname in commit header ***","fromName":"Arnaud Bertrand","fromEmail":"arnaud.bertrand@abalgo.com","sentAt":"2019-12-30T10:33:13Z","receivedAt":"2019-12-30T10:33:28Z","isPatch":true,"sender":{"key":"arnaud.bertrand@abalgo.com","avatar":null},"body":"Hello Brian,\n\nLe lun. 30 déc. 2019 à 03:33, brian m. carlson\n<sandals@crustytoothpaste.net> a écrit :\n>\n> On 2019-12-29 at 22:26:32, Arnaud Bertrand wrote:\n> > From: Arnaud Bertrand <xda@abalgo.com>\n> >\n> > For tracability purpose it is often necessary to know which\n> > commit is envolved in a branch\n> > Keeping track of the branchname in the commit header\n> > will make this traceability easy and will facilitate\n> > the graphical toolis that represent the branches and\n> > that have today to use complex algorithm to try to\n> > determine the branch of a commit that was known at\n> > the commit time.\n> >\n> > no big change in the code, today rebase is not considered yet\n> > I'm waiting feedback about that before touching\n> > the rebase code.\n>\n> I encourage you to read back in the history of the list as to why we\n> haven't done this and why it's not likely to be accepted now, but let me\n> provide a few reasons of my own.\n>\n> First, as any contributor to the mailing list can tell you, I am\n> absolutely terrible at naming things.  I frequently name my branches\n> something that makes sense to me at the time without regard to whether\n> that will make sense in the future.  I don't want to memorialize my\n> momentary thoughtlessness in the history of the repository forever.\n>\n\nI think you got the point! Git is written by software people for\nsoftware people and we know that we don't like to keep track of our\nmistakes... Git allows you to to work like this because you can have\nyour own local branches with the name you want, just use a git merge\n--no-ff at the end and only the commits that make senses will be in\nthe repository forever.\nFor CMM compliance, the branch type and the branch name must be\ndescribed in a SCM plan. In big open source project, I understand it\nis not the so important because, at the end, we will only integrate\none patch on the master trunk, it is not like this for most of the\nprojects in companies.\n\n> Second, one workflow I commonly use is creating a branch with many\n> commits and then breaking them down into small series that are logical\n> and easy for review.  If I have a branch called \"test-fixes-part7\" with\n> 50 commits and then I decide to split that into two branches,\n> test-fixes-part7 and test-fixes-part8, by copying the branch and using\n> git reset --hard to truncate the old one, I don't want the old branch\n> name in my new branch.  A lot of Git workflows assume you can reset and\n> rename branches this way and having the branch name in the commit header\n> breaks those workflows.\n\nI understand but it will not break the workflow. .. the fact to have\nthe branchname as information in the commit header could be no more\nthan an \"additional information\". Exactly as you name and email is in\nthe commit header too It is simply an additional information for those\nwho want it, who need it. If you don't want to use is, that's right,\nthis information is even not visible in a normal git log command.It is\nonly visible with a dedicated placeholder.\n\n>\n> Third, people reuse branch names.  Right now, I have eight branches with\n> test fixes all starting with \"test-fixes-part\" because I'm working on\n> one major project with all of those test fixes.  However, if a developer\n> working on another major project also has a lot of changes to the test\n> suite, they may have lots of identically named branches, which would be\n> confusing, since our identically named test fix branches would relate to\n> different projects.  (See my first point.)\n\nIf it is different projects... it will not be confusing. And again,\nyou have 2 situations:\n1. People working with SCM plan and hard branch naming convention. In\nthis case, they will never get this kind of problem, duplicated name\nare impossible \"by construction\"\n2. People that are working with temporary branch will not use the\nbranchname in the header and having duplicate branchname will no be\nconfusing.\n\n>\n> However, despite the fact that we aren't likely to add this in the\n> commit header, there are definitely ways to achieve this.\n>\n\nI agree with the exception of the fact that it will depend on the\nthoroughness of the developers themselves. And it will be more risky\nto develop new features that has to be confident in the commit\nmessage.\n\n> If you want to include the branch name in the commit, you can do so with\n> a trailer.  git interpret-trailers can then be used to manipulate and\n> extract these, and along with a hook, add them automatically if they're\n> missing.\n\nUnfortunately, hooks are (can be) personal and there no way I know to\nforce a hook to be used. That exactly what I was using today but a lot\nof developer that start on the project, clone it but does not use the\ncorrect hook. So, finally, It is impossible to be confident in the\ncommit message content to get the name of the branch.\n\nLet me explain our workflow (which is a really common one):\nEveryday, for backup reasons, all developers have to push their work\non the central repository (at least their major development branch,\nnot the experimental). In this context, the rebase is not used (should\neven be forbidden) but we are using the \"merge back\" instead (merge\nmaster to localdev) very often to guarantee the coherence between the\ncurrent master state and the development..\nAt the end of each \"small development\" (bug fix or feature request),\nthe branch is merged with no fast-forward.\nSo we have this kind of graph:\n\n*   d122671 (HEAD -> master) master: Merge branch 'dev_feature1'\n|\\\n| * 7a6a93d (dev_feature1) dev_feauture1: some new changes\n| *   9e498de Merge branch 'master' into dev_feature1\n| |\\\n| |/\n|/|\n* | 2fca855 master: feature x merged\n| * 3610279 dev_feauture1: some other changes\n| * ae69fa8 dev_feauture1: some changes\n|/\n* 8bfee18 master:current status\n\nAs you can see, to explain the flow I had to add the branchname on\neach commit ;-)\n\nSo, each new version in the master branch is the result of merge\n(exactly what you are doing when you integrate patch) but with\ndifference that we want to keep track of feature history and we want\nto be confident in the tool, not in the rigor of our developers. And\nwe don't want to see the development commits as history of the master\nversion:\nTo be more clear, the master previous version is 2fca, not 7a6a nor 9e49.\nAnd it is important to have that view to answer a lot of question\n(why, when, what, who, which effort, how long, how many, ... )\n\n>\n> If you're working on a more centralized project and you want to require\n> the branch name in your commit trailers, you can set your CI system to\n> fail or reject commits that don't contain them.  This is the approach\n> that systems like Gerrit use when the required trailers are missing and\n> it seems to work reasonably well.\n\nI don't know gerrit but I think it is an something that use git as\nkernel but I don't know if developers have directly access to the git\nrepository. or has to use the web interface.\nof course, with a upper layer, everything is still possible.\n\n>\n> Hopefully these suggestions are helpful in getting you the traceability\n> you desire without requiring fundamental changes to the way Git works.\n\nAgain, what I propose is certainly not a fundamental change but just\nan additional metadata to help those who need it.\nI even propose to configure a variable to activate it (even if I\nprefer it is activated by default to be sure it is done by new users).\nI will publish the patch with the variable but I've seen a small bug\nto fix before ;-)\n\nThanks for your feedback,\n\nArnaud\n\n> --\n> brian m. carlson: Houston, Texas, US\n> OpenPGP: https://keybase.io/bk2204\n"},{"id":"389072","messageId":"20191230163256.14749-1-xda@abalgo.com","threadId":"52536","inReplyTo":"20191229222633.23815-1-arnaud.bertrand@abalgo.com","subject":"[RFC PATCH 0/2 v2] *** Add branchname in commit when core.branchnameincommit is set ***","fromName":"Arnaud Bertrand","fromEmail":"xda@abalgo.com","sentAt":"2019-12-30T16:32:54Z","receivedAt":"2019-12-30T16:33:21Z","isPatch":true,"sender":{"key":"xda@abalgo.com","avatar":null},"body":"To avoid any change in the current git behaviour by default, I've added\na configuration variable that allow to activate the feature for those\nwho want to see the branchname in commit. \nBy default, this feature is disabled\n\nArnaud Bertrand (2):\n  Add branchname in commit header\n  Add the configuration parameter core.branchnameincommit\n\n Documentation/pretty-formats.txt |  1 +\n cache.h                          |  1 +\n commit.c                         | 21 +++++++++++++++++++++\n config.c                         |  5 +++++\n environment.c                    |  1 +\n pretty.c                         | 15 +++++++++++++++\n 6 files changed, 44 insertions(+)\n\n-- \n2.25.0.rc0.7.g17b02bf28a\n\n"},{"id":"389073","messageId":"20191230163256.14749-2-xda@abalgo.com","threadId":"52536","inReplyTo":"20191230163256.14749-1-xda@abalgo.com","subject":"[RFC PATCH 1/2 v2] Add branchname in commit header","fromName":"Arnaud Bertrand","fromEmail":"xda@abalgo.com","sentAt":"2019-12-30T16:32:55Z","receivedAt":"2019-12-30T16:33:25Z","isPatch":true,"sender":{"key":"xda@abalgo.com","avatar":null},"body":"Add the branchname in the commit header before the commit message\nthe following line is added:\n\nbranch <branchname>\n\nwhere <branchname> comes from the function resolve_ref_unsafe(\"HEAD\",...)\nwithout the prefix refs/heads/\nA placeholder is added to the pretty format \"%Xb\" to print the branch information,\nX if for \"extra-header\" and can be use in the future for new features\nb is of course for \"branch\"\n\nthe %Xb returns an empty string when branchname information is not found\n---\n Documentation/pretty-formats.txt |  1 +\n commit.c                         | 11 +++++++++++\n pretty.c                         | 15 +++++++++++++++\n 3 files changed, 27 insertions(+)\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex 1a7212ce5a..bd52908f53 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -241,6 +241,7 @@ endif::git-rev-list[]\n '%gE':: reflog identity email (respecting .mailmap, see\n \tlinkgit:git-shortlog[1] or linkgit:git-blame[1])\n '%gs':: reflog subject\n+'%Xb':: branchname in which commit was done\n '%(trailers[:options])':: display the trailers of the body as\n \t\t\t  interpreted by\n \t\t\t  linkgit:git-interpret-trailers[1]. The\ndiff --git a/commit.c b/commit.c\nindex 434ec030d6..f64a0698be 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1425,6 +1425,9 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \tint result;\n \tint encoding_is_utf8;\n \tstruct strbuf buffer;\n+\tconst char *branch = \"Unknown\";\n+\tint flags;\n+\tconst char *lbranch =resolve_ref_unsafe(\"HEAD\",0,NULL,&flags);\n \n \tassert_oid_type(tree, OBJ_TREE);\n \n@@ -1453,6 +1456,14 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \t\tauthor = git_author_info(IDENT_STRICT);\n \tstrbuf_addf(&buffer, \"author %s\\n\", author);\n \tstrbuf_addf(&buffer, \"committer %s\\n\", git_committer_info(IDENT_STRICT));\n+\tif (lbranch) {\n+\t   skip_prefix(lbranch,\"refs/heads/\",&branch);\n+\t   strbuf_addf(&buffer, \"branch %s\\n\", branch);\n+\t}\n+\telse {\n+\t   strbuf_addf(&buffer, \"branch Unknown\\n\");\n+\t}\n+\n \tif (!encoding_is_utf8)\n \t\tstrbuf_addf(&buffer, \"encoding %s\\n\", git_commit_encoding);\n \ndiff --git a/pretty.c b/pretty.c\nindex 305e903192..5961c39398 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -804,6 +804,7 @@ struct format_commit_context {\n \n \t/* The following ones are relative to the result struct strbuf. */\n \tsize_t wrap_start;\n+\tchar *branch;\n };\n \n static void parse_commit_header(struct format_commit_context *context)\n@@ -1367,6 +1368,20 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */\n \t\treturn 1;\n \t}\n \n+\n+\t/* Now add extra header info */\n+\tif (placeholder[0] == 'X') {\n+\t\tswitch (placeholder[1]) {\n+\t\tcase 'b': /* branch ... */\n+\t\t\tc->branch = get_header(msg,\"branch\");\n+\t\t\tif (c->branch)\n+\t\t\t\tstrbuf_addstr(sb, c->branch);\n+\t\t\tfree(c->branch);\n+\t\t\treturn 2;\n+\t\t}\n+\t}\n+\n+\n \t/* Now we need to parse the commit message. */\n \tif (!c->commit_message_parsed)\n \t\tparse_commit_message(c);\n-- \n2.25.0.rc0.7.g17b02bf28a\n\n"},{"id":"389074","messageId":"20191230163256.14749-3-xda@abalgo.com","threadId":"52536","inReplyTo":"20191230163256.14749-1-xda@abalgo.com","subject":"[RFC PATCH 2/2 v2] Add the configuration parameter core.branchnameincommit","fromName":"Arnaud Bertrand","fromEmail":"xda@abalgo.com","sentAt":"2019-12-30T16:32:56Z","receivedAt":"2019-12-30T16:33:26Z","isPatch":true,"sender":{"key":"xda@abalgo.com","avatar":null},"body":"With this parameter, which is 0 by default (no change compare\nto the normal behaviour) you have the possibility to activate\nthis feature to have the branchname in the header commit\nWhen it exists, the branchname is accesible in the git log\nwith the pretty format placehoder \"%Xb\".\n---\n cache.h       |  1 +\n commit.c      | 24 +++++++++++++++++-------\n config.c      |  5 +++++\n environment.c |  1 +\n 4 files changed, 24 insertions(+), 7 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 1554488d66..dd7188a4e4 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -949,6 +949,7 @@ void reset_shared_repository(void);\n  * commands that do not want replace references to be active.\n  */\n extern int read_replace_refs;\n+extern int branchname_in_commit;\n extern char *git_replace_ref_base;\n \n extern int fsync_object_files;\ndiff --git a/commit.c b/commit.c\nindex f64a0698be..e63d97d308 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1428,6 +1428,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \tconst char *branch = \"Unknown\";\n \tint flags;\n \tconst char *lbranch =resolve_ref_unsafe(\"HEAD\",0,NULL,&flags);\n+\tint flbranchinextra = 0;\n \n \tassert_oid_type(tree, OBJ_TREE);\n \n@@ -1456,21 +1457,30 @@ int commit_tree_extended(const char *msg, size_t msg_len,\n \t\tauthor = git_author_info(IDENT_STRICT);\n \tstrbuf_addf(&buffer, \"author %s\\n\", author);\n \tstrbuf_addf(&buffer, \"committer %s\\n\", git_committer_info(IDENT_STRICT));\n-\tif (lbranch) {\n-\t   skip_prefix(lbranch,\"refs/heads/\",&branch);\n-\t   strbuf_addf(&buffer, \"branch %s\\n\", branch);\n-\t}\n-\telse {\n-\t   strbuf_addf(&buffer, \"branch Unknown\\n\");\n-\t}\n \n \tif (!encoding_is_utf8)\n \t\tstrbuf_addf(&buffer, \"encoding %s\\n\", git_commit_encoding);\n \n \twhile (extra) {\n+\t\t/* when commit is reworked - e.g. amend, the banch is already\n+\t\t * in extra-header and must not be modified\n+\t\t*/\n+\t\tif (!strcmp(extra->key,\"branch\"))\n+\t\t\tflbranchinextra=1;\n \t\tadd_extra_header(&buffer, extra);\n \t\textra = extra->next;\n \t}\n+\n+\tif (branchname_in_commit && !flbranchinextra) {\n+\t\tif (lbranch) {\n+\t\t\tskip_prefix(lbranch,\"refs/heads/\",&branch);\n+\t\t\tstrbuf_addf(&buffer, \"branch %s\\n\", branch);\n+\t\t}\n+\t\telse {\n+\t\t\tstrbuf_addf(&buffer, \"branch Unknown\\n\");\n+\t\t}\n+\t}\n+\n \tstrbuf_addch(&buffer, '\\n');\n \n \t/* And add the comment */\ndiff --git a/config.c b/config.c\nindex d75f88ca0c..bec1b5c3af 100644\n--- a/config.c\n+++ b/config.c\n@@ -1389,6 +1389,11 @@ static int git_default_core_config(const char *var, const char *value, void *cb)\n \t\treturn 0;\n \t}\n \n+\tif (!strcmp(var, \"core.branchnameincommit\")) {\n+\t\tbranchname_in_commit = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n+\n \t/* Add other config variables here and to Documentation/config.txt. */\n \treturn platform_core_config(var, value, cb);\n }\ndiff --git a/environment.c b/environment.c\nindex e72a02d0d5..1d266a91cf 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -52,6 +52,7 @@ const char *askpass_program;\n const char *excludes_file;\n enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;\n int read_replace_refs = 1;\n+int branchname_in_commit = 0;\n char *git_replace_ref_base;\n enum eol core_eol = EOL_UNSET;\n int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;\n-- \n2.25.0.rc0.7.g17b02bf28a\n\n"}]}