Skip to contentSkip to conversation

Feature request: git-pull -e/--edit

PATCH In review [email protected] 7 participants 14 messages Aug 11, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

The last end-user use I can think of for git-merge instead of git-pull is providing a custom commit message.

Would it be possible to add -m and -e options to git-pull?

The problem I can see is that the latter would have to be added to git-merge, and the guts there are a bit intricate; it uses git-commit-tree directly rather than git-commit, so I can't just pass through the arguments.

Assuming it's just as much of a pain for someone else, would it still be worth the effort? Can git-merge be cleaned up?

The manual option is to use "git merge --no-commit" and then supply the arguments to git-commit in the usual way.

But I notice that --no-commit actually changes git's merging technique. If it's specified, the trivial in-index merge doesn't appear to be attempted. I don't think it makes a huge difference,

#1 lore raw
Quoted 9 lines · [email protected] writes:

The last end-user use I can think of for git-merge instead of git-pull is providing a custom commit message.

Would it be possible to add -m and -e options to git-pull?

The problem I can see is that the latter would have to be added to git-merge, and the guts there are a bit intricate; it uses git-commit-tree directly rather than git-commit, so I can't just pass through the arguments.

How often is this desired, when the merge is clean?

If the answer is "not so often", you can already use "commit --amend" after "pull" creates an automated merge commit.

#2 lore raw
Quoted 1 line

How often is this desired, when the merge is clean?

Well, if I could quote your own words:

Quoted 5 lines
Quoted 5 lines

I use "git pull . topicA topicB" for a tetrapus, so that is not a reason for me, but when a topicA's older parts are worthy to be in 'next' while later parts are not yet, I often do (on 'next'):

git merge "Merge early part of branch 'topicA'" HEAD topicA~3

I can't speak from personal experience, but a merge can bring in a lot of changes, and sometimes the auto-generated message doesn't say quite as much as you'd like.

The commits on the branch speak for themselves, of course, but sometimes it's nice to add the same sort of overview that appears in a [PATCH 0/13] e-mail. We wouldn't have that convention if there wasn't a frequent desire for it.

(Indeed, it might be nice to come up with a way of including a piece of the "please pull" e-mail, similar to the way that git-applypatch works.)

Quoted 2 lines

If the answer is "not so often", you can already use "commit --amend" after "pull" creates an automated merge commit.

It's not done very often right now, but how much of that is due to the awkwardness? I agree it works perfectly, but "commit --amend" has very much the feel of a workaround.

I'm not going to besiege Troy for a decade over the idea, but it seemed

#3 lore raw
Quoted 8 lines · [email protected] writes:
Quoted 1 line

How often is this desired, when the merge is clean?

Well, if I could quote your own words:

Quoted 4 lines
Quoted 4 lines

I use "git pull . topicA topicB" for a tetrapus, so that is not a reason for me, but when a topicA's older parts are worthy to be in 'next' while later parts are not yet, I often do (on 'next'):

Quoted 5 lines
Quoted 1 line
Quoted 1 line

git merge "Merge early part of branch 'topicA'" HEAD topicA~3

I can't speak from personal experience, but a merge can bring in a lot of changes, and sometimes the auto-generated message doesn't say quite as much as you'd like.

That is more or less irrelevant example. I was only saying that it is a workaround to emulate "git pull . topicA~3"; if that form worked, I would keep the automated fmt-merge-msg output that is currently recorded in the merge and I do not see any need to edit it further.

Quoted 2 lines

(Indeed, it might be nice to come up with a way of including a piece of the "please pull" e-mail, similar to the way that git-applypatch works.)

That is a lot more relevant example. For example, I could imagine that Linus coming up with a wrapper that is fed a series of e-mails and:

* if it is a patch, run git-applymbox on it as before,

* if it is a pull request, then extract the URL and branch, run "git pull" on that, match the "diff ORIG_HEAD" output against what is in the pull request and,

- warn if there are huge discrepancies;

- otherwise annotate the commit message with the explanation of the series taken from the pull request message.

But even in that workflow, "annotate the commit" comes after pull happens and the merge result is verified, so I do not quite see "commit --amend" as a "workaround" as you said.

Having said that, I think the real reason that the whole "merge" message generation feels awkward comes from the historical division of labor between pull and merge.

"git merge" started its life as the first level command (with a funny syntax that does not even take command line option -m, because you are supposed to give the whole merge message and "git merge" itself does not do anything to affect the merge message on its own). When it was pushed further back to the "worker behind the scene" status, the task of coming up with a fancier automated merge message were still left to the "git pull" command which (1) is the UI level command that the users are expected to use, and (2) knows much more about the context where the merge is generated than "git merge" itself. As a result, "git merge" still takes the whole message prepared and it does not do anything on its own.

So if we rename the current "git merge" to "git-merge--record" (or any name "git pull" uses internally to record the merge commit), and make "git merge" a synonym to "git pull .", and give a command line option -m to "git pull" to _affect_ the resulting merge message, I would think everybody would become quite happy. It means:

- People can say "git merge this-branch" (which is internally translated to "git pull . this-branch");

- People can say "git pull -m 'I am doing this merge for such and such reason' $URL $branch" to _include_ that message in the resulting merge commit;

- The same can be said about "git merge -m 'comment' $branch".

I said _affect_ and _include_ in the above because I suspect that most of the time you do not want to _replace_ the autogenerated part ("Merge branch of repo", and if you are pulling from your subordinate trees the merge summary message as well).

#4 lore raw

PATCH 1/1 git-merge: make it usable as the first class UI

Quoted 14 lines · Junio C Hamano

So if we rename the current "git merge" to "git-merge--record" (or any name "git pull" uses internally to record the merge commit), and make "git merge" a synonym to "git pull .", and give a command line option -m to "git pull" to _affect_ the resulting merge message, I would think everybody would become quite happy. It means:

- People can say "git merge this-branch" (which is internally translated to "git pull . this-branch");

- People can say "git pull -m 'I am doing this merge for such and such reason' $URL $branch" to _include_ that message in the resulting merge commit;

Quoted 7 lines

- The same can be said about "git merge -m 'comment' $branch".

I said _affect_ and _include_ in the above because I suspect that most of the time you do not want to _replace_ the autogenerated part ("Merge branch of repo", and if you are pulling from your subordinate trees the merge summary message as well).

I did a moral equivalent of the above without renaming the command "git merge" and will be pushing the result out in "pu" shortly.

The following is for commenting only -- it depends on an earlier patch in "pu".

-- >8 --
[PATCH] git-merge: make it usable as the first class UI

This teaches the oft-requested syntax

git merge $commit

to implement merging the named commit to the current branch. This hopefully would make "git merge" usable as the first class UI instead of being a mere backend for "git pull".

Most notably, $commit above can be any committish, so you can say for example:

git merge js/shortlog~2

to merge early part of a topic branch without merging the rest of it.

A custom merge message can be given with the new --message=<msg> parameter. The message is prepended in front of the usual "Merge ..." message autogenerated with fmt-merge-message.

---
 Documentation/git-merge.txt |   18 +++++++++---
 git-merge.sh                |   61 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 67 insertions(+), 12 deletions(-)
Documentation/git-merge.txt +13 -5
index bebf30a..e2954aa 100644
@@ -8,12 +8,14 @@ git-merge - Grand Unified Merge Driver
 
 SYNOPSIS
 --------
-'git-merge' [-n] [--no-commit] [-s <strategy>]... <msg> <head> <remote> <remote>...
-
+[verse]
+'git-merge' [-n] [--no-commit] [--squash] [-s <strategy>]...
+	[--reflog-action=<action>]
+	-m=<msg> <remote> <remote>...
 
 DESCRIPTION
 -----------
-This is the top-level user interface to the merge machinery
+This is the top-level interface to the merge machinery
 which drives multiple merge strategy scripts.
 
 
@@ -27,13 +29,19 @@ include::merge-options.txt[]
 	to give a good default for automated `git-merge` invocations.
 
 <head>::
-	our branch head commit.
+	Our branch head commit.  This has to be `HEAD`, so new
+	syntax does not require it
 
 <remote>::
-	other branch head merged into our branch.  You need at
+	Other branch head merged into our branch.  You need at
 	least one <remote>.  Specifying more than one <remote>
 	obviously means you are trying an Octopus.
 
+--reflog-action=<action>::
+	This is used internally when `git-pull` calls this command
+	to record that the merge was created by `pull` command
+	in the `ref-log` entry that results from the merge.
+
 include::merge-strategies.txt[]
 
 
git-merge.sh +54 -7

85 lines not on this page · raw message

Signature · 1 line
1.4.4.gbacc
#5 lore raw

Re: [PATCH] git-merge: make it usable as the first class UI

Junio C Hamano <[email protected]> wrote:

[...]

Quoted 11 lines

-- >8 --
[PATCH] git-merge: make it usable as the first class UI

This teaches the oft-requested syntax

git merge $commit

to implement merging the named commit to the current branch. This hopefully would make "git merge" usable as the first class UI instead of being a mere backend for "git pull".

Quoted 7 lines

Most notably, $commit above can be any committish, so you can say for example:

git merge js/shortlog~2

to merge early part of a topic branch without merging the rest of it.

"Early part", i.e., branch js/shortlog up to js/shortlog~2 or just that one commit?

Quoted 3 lines

A custom merge message can be given with the new --message=<msg> parameter. The message is prepended in front of the usual "Merge ..." message autogenerated with fmt-merge-message.

Why not -m too (consistency!)?

Signature · 3 lines
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                    Fono: +56 32 2654431
Universidad Tecnica Federico Santa Maria             +56 32 2654239
#6 lore raw

Re: [PATCH] git-merge: make it usable as the first class UI

Quoted 10 lines · Horst H. von Brand
Quoted 7 lines

Most notably, $commit above can be any committish, so you can say for example:

git merge js/shortlog~2

to merge early part of a topic branch without merging the rest of it.

"Early part", i.e., branch js/shortlog up to js/shortlog~2 or just that one commit?

"Early part up to that commit" -- this is not a cherry pick.

Quoted 5 lines
Quoted 3 lines

A custom merge message can be given with the new --message=<msg> parameter. The message is prepended in front of the usual "Merge ..." message autogenerated with fmt-merge-message.

Why not -m too (consistency!)?

That form also is accepted, I think.

#7 lore raw
In reply to Junio C Hamano
Quoted 1 line · Junio C Hamano

So if we rename the current "git merge" to "git-merge--record"

or git-merge-driver

Quoted 13 lines

(or any name "git pull" uses internally to record the merge commit), and make "git merge" a synonym to "git pull .", and give a command line option -m to "git pull" to _affect_ the resulting merge message, I would think everybody would become quite happy.  It means:

 - People can say "git merge this-branch" (which is internally translated to "git pull . this-branch");

 - People can say "git pull -m 'I am doing this merge for such and such reason' $URL $branch" to _include_ that message in the resulting merge commit;

Quoted 7 lines

 - The same can be said about "git merge -m 'comment' $branch".

I said _affect_ and _include_ in the above because I suspect that most of the time you do not want to _replace_ the autogenerated part ("Merge branch of repo", and if you are pulling from your subordinate trees the merge summary message as well).

I'm all for adding -m <msg> option to git-pull (and perhaps also common other message generation options: -F <file>, --edit). I'm even for adding -m option to git-merge.

Making "git merge" to be a synonym to "git pull ."... I'm not so sure. I'd rather we don't lose the ability to give arbitrary refs ar "other" heads like in

git merge "Merge early part of branch 'topicA'" HEAD topicA~3

example, and ability (if there is such ability) to not include HEAD (current version of branch) as first parent like in

git checkout pu
git merge "Merge branch 'topicA', 'topicB'" topicA topicB

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#8 lore raw
In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 2 lines · [email protected] writes:

(Indeed, it might be nice to come up with a way of including a piece of the "please pull" e-mail, similar to the way that git-applypatch works.)

That is a lot more relevant example. For example, I could imagine that Linus coming up with a wrapper that is fed a series of e-mails and:

[snip]

Quoted 2 lines

- otherwise annotate the commit message with the explanation of the series taken from the pull request message.

[snip]

Quoted 5 lines

- People can say "git pull -m 'I am doing this merge for such and such reason' $URL $branch" to _include_ that message in the resulting merge commit;

- The same can be said about "git merge -m 'comment' $branch".

What about fast forwards? Do you get to record the explanation for the series only if the guy you pulled from didn't bother to do a rebase? That's broken.

Let's face it, the merge commits generated when pulling have two completely independent uses:
1. They're technically necessary for joining DAG nodes that don't all lie on one path.
2. They're useful as a record of workflow and a place to put comments.

The two uses are nearly independent.
Consider the following silly DAG.

A------------F master
\ /

    B--C--D--E

Yes, E and F have identical trees. But it's actually *very useful*, if the commit message at F says "merged branch foo containing experimental bar from quux". And it shows up nicely when looking at gitk.

Of course, you could just fast-forward instead:

A--B--C--D--E master

but then you lose a meaningful and useful part of the historical record.

There are the obvious bad consequences if you make this the default, but how about adding a --force-commit option to merge and pull?

You'd need to educate users on how to use this responsibly to avoid noise, but that's not any different from existing stuff like rebase and revert. Most users won't even know it exists.

And to answer Linus: yes, it's expected that only non-leaf developers will use --force-commit on regular basis, but that's not because maintainers are technically special in any way. It's just because maintainers have something useful to say ("someone's private topic branch, starting at A and ending at E, has just been accepted into my all-important public repo and here's why"). Anyone else can do the same if he feels likewise.

#9 lore raw

Eran Tromer <[email protected]> wrote:

[...]

Quoted 13 lines

What about fast forwards? Do you get to record the explanation for the series only if the guy you pulled from didn't bother to do a rebase? That's broken.

Let's face it, the merge commits generated when pulling have two completely independent uses:
1. They're technically necessary for joining DAG nodes that don't all lie on one path.
2. They're useful as a record of workflow and a place to put comments.

The two uses are nearly independent.
Consider the following silly DAG.

Quoted 7 lines

A------------F master
\ /

    B--C--D--E

Yes, E and F have identical trees. But it's actually *very useful*, if the commit message at F says "merged branch foo containing experimental bar from quux". And it shows up nicely when looking at gitk.

I don't see the usefulness of this.

Quoted 3 lines

Of course, you could just fast-forward instead:

A--B--C--D--E master

Yep.

Quoted 1 line

but then you lose a meaningful and useful part of the historical record.

And if quux merges back, she gets the same plus a new merge node, and... Linus told everybody (quite forcefully, I might add) that this is not acceptable for distributed development.

Quoted 2 lines

There are the obvious bad consequences if you make this the default, but how about adding a --force-commit option to merge and pull?

Fast forward is fast forward. Merge is when /independent/ changes are integrated into one.

Quoted 1 line

You'd need to educate users on how to use this responsibly

Looks like you've never met real users ;-)

Quoted 11 lines

to avoid
noise, but that's not any different from existing stuff like rebase and revert. Most users won't even know it exists.

And to answer Linus: yes, it's expected that only non-leaf developers will use --force-commit on regular basis, but that's not because maintainers are technically special in any way. It's just because maintainers have something useful to say ("someone's private topic branch, starting at A and ending at E, has just been accepted into my all-important public repo and here's why"). Anyone else can do the same if he feels likewise.

But the individual changes will presumably reflect said someone's authorship. If they are interleaved with stuff by others or not doesn't make much (development) sense. Yes, it might be interesting for a software historian, but that's not git's main audience in the first place.

Signature · 3 lines
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                    Fono: +56 32 2654431
Universidad Tecnica Federico Santa Maria             +56 32 2654239
#10 lore raw
Quoted 10 lines · Horst H. von Brand
Quoted 8 lines

A------------F master
\ /

    B--C--D--E

Yes, E and F have identical trees. But it's actually *very useful*, if the commit message at F says "merged branch foo containing experimental bar from quux". And it shows up nicely when looking at gitk.

I don't see the usefulness of this.

Just look up this thread for the most recent example: recording the text of "pull foo to get" and "[00/05] Fix quux" message.

Quoted 3 lines

And if quux merges back, she gets the same plus a new merge node, and... Linus told everybody (quite forcefully, I might add) that this is not acceptable for distributed development.

I've address this. Sure, it breaks down completely if done by default when nothing new happens; but not when done judiciously. For real problems to show up you'd need two people who both insist on always using --force-commit when pulling each other. Inevitably, before long they will realize the folly of their ways and stop doing that; problem solved.

I expect common usage to be that --force-commit is only used by maintainers, when pulling/applying non-trivial branches from downstream. But this is a social convention that can be decided per project, and can be ignored by anyone who decides to fork off. And if Linus doesn't like it he can just avoid using it in his projects.

Quoted 5 lines
Quoted 2 lines

There are the obvious bad consequences if you make this the default, but how about adding a --force-commit option to merge and pull?

Fast forward is fast forward. Merge is when /independent/ changes are integrated into one.

I was under the impression that git-merge is what (indirectly) determines if joining multiple commits is a fast-forward or a real merge. If it's in some other piece of git, please substitute that.

Quoted 3 lines
Quoted 1 line

You'd need to educate users on how to use this responsibly

Looks like you've never met real users ;-)

No, it's really easy in this case: if someone asks you to pull a rotten branch with too many forced merges, just refuse until he stops abusing that option. It's not the default, right? There are plenty of much worse non-default ways to damage history.

Quoted 8 lines
Quoted 7 lines

And to answer Linus: yes, it's expected that only non-leaf developers will use --force-commit on regular basis, but that's not because maintainers are technically special in any way. It's just because maintainers have something useful to say ("someone's private topic branch, starting at A and ending at E, has just been accepted into my all-important public repo and here's why"). Anyone else can do the same if he feels likewise.

Quoted 4 lines

But the individual changes will presumably reflect said someone's authorship. If they are interleaved with stuff by others or not doesn't make much (development) sense. Yes, it might be interesting for a software historian, but that's not git's main audience in the first place.

If the only thing you care about is the tree of the top commit, then sure, those redundant commits are worthless. But then, why do you bother with (for example) commit messages, or tag objects? Oh, you want to know more about what happened and why? Then great, those "pull foo to get" and "[00/05]" messages are probably the best place to start, if we only had where to save them.

We are all "software historians" when we look at some project's public branches and try to grok what's going on recently, who's doing what and along what workflow, and why it got there. This is useful information, that is not easily tracked by any other means; there's a reason this comes up repeatedly in various guises, you know. I can't see why some people are so eager to discard this information and tell others to use a munged-up shortlogs, instead of looking for ways to record as much possible with the least negative impact.

Now, --force-commit with appropriate usage conventions seems like a reasonable tradeoff.

BTW, in principle another (better?) way to do it is by leaving the commit DAG alone, and annotating it with tag objects where extra information such as "[00/05]" is available. The problem is that git doesn't have any scalable mechanism for adding such annotations. It's a hard problem; nothing in the commit DAG points to to tag objects, so you have to scan some external store and that gets more expensive as the repo grows. It also gets nasty in fetches.

Eran

#11 lore raw

Hi,

Quoted 7 lines · Eran Tromer
Quoted 6 lines · Horst H. von Brand
Quoted 6 lines

A------------F master
\ /

    B--C--D--E

Yes, E and F have identical trees.

There has been only _one_ line of history, so why introduce what was not there?

It sounds more like you do not trust "E" to be something especially useful, but in that case you should not merge it to begin with.

Ciao,

#12 lore raw
In reply to Horst H. von Brand
Quoted 4 lines · Horst H. von Brand
Quoted 3 lines · Eran Tromer

A------------F master
\ /

    B--C--D--E

..snip..

Quoted 3 lines

And if quux merges back, she gets the same plus a new merge node, and... Linus told everybody (quite forcefully, I might add) that this is not acceptable for distributed development.

Wrong, if quux merges back and does not do the same "force commit" fast-forward (why would it, anyway - OP clearly said it's only if you _want_ to make it explicit), quux won't get another merge but end up with F as well. It all converges back nicely.

I can see how it could be useful.

Quoted 3 lines
Quoted 1 line

You'd need to educate users on how to use this responsibly

Looks like you've never met real users ;-)

Yes, that is a real problem. ;-) But not adding features because users could use them irresponsibly doesn't get you too far.

Quoted 10 lines
Quoted 7 lines

And to answer Linus: yes, it's expected that only non-leaf developers will use --force-commit on regular basis, but that's not because maintainers are technically special in any way. It's just because maintainers have something useful to say ("someone's private topic branch, starting at A and ending at E, has just been accepted into my all-important public repo and here's why"). Anyone else can do the same if he feels likewise.

But the individual changes will presumably reflect said someone's authorship.

You are personifying too much. Git setups where multiple people have commit access are very common, and there's no reason to play them down just because Git makes other setups easy.

Quoted 3 lines

If they are interleaved with stuff by others or not doesn't make much (development) sense. Yes, it might be interesting for a software historian, but that's not git's main audience in the first place.

Tell that to Junio, our pickaxe guy. :^)

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
The meaning of Stonehenge in Traflamadorian, when viewed from above, is:
"Replacement part being rushed with all possible speed."
#13 lore raw
In reply to [email protected]
Quoted 4 lines · [email protected] writes:

But I notice that --no-commit actually changes git's merging technique. If it's specified, the trivial in-index merge doesn't appear to be attempted. I don't think it makes a huge difference, but is any difference desirable?

This was done in response to a specific request from the list but I do not remember the details. If I were to research the background I would

(1) first, look at the authordate of the commit that introduced the change. For this, I would most likely use:

git log -p -S--no-commit -- git-pull.sh

(2) go back to the list archive and find the thread that predates that commit by a few days.