{"thread":{"id":"19435","subject":"git merge remote branch says \"Merge commit ...\"?","startedAt":"2009-05-21T19:50:48Z","lastAt":"2009-05-25T09:44:52Z","messageCount":10,"participants":["skillzero@gmail.com","Jeff King","Eric Raible","Johannes Sixt","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114440","messageId":"2729632a0905211250v4e7537caybe9e703c14361b5f@mail.gmail.com","threadId":"19435","inReplyTo":null,"subject":"git merge remote branch says \"Merge commit ...\"?","fromName":"","fromEmail":"skillzero@gmail.com","sentAt":"2009-05-21T19:50:48Z","receivedAt":"2009-05-21T19:50:48Z","isPatch":false,"sender":{"key":"skillzero@gmail.com","avatar":null},"body":"I noticed that if I do 'git merge origin/branch' that the log message\nsays (using --log):\n\nMerge commit 'origin/branch'\n\n   * commit 'origin/branch':\n     Fixed some bug.\n\nIf I do the same thing from a local tracking branch of origin/branch, it says:\n\nMerge branch 'branch'\n\n   * branch:\n     Fixed some bug.\n\nIs it expected that it say \"commit\" instead of \"branch\" when the\nbranch is not a local tracking branch? I sometimes merge from remote\nbranches when I don't need to do anything with that branch locally\n(e.g. I already did the work on another computer and I'm just merging\nthe result into my test machine before I push to the shared server).\n"},{"id":"114453","messageId":"20090522074927.GB1409@coredump.intra.peff.net","threadId":"19435","inReplyTo":"2729632a0905211250v4e7537caybe9e703c14361b5f@mail.gmail.com","subject":"Re: git merge remote branch says \"Merge commit ...\"?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-22T07:49:27Z","receivedAt":"2009-05-22T07:49:27Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, May 21, 2009 at 12:50:48PM -0700, skillzero@gmail.com wrote:\n\n> I noticed that if I do 'git merge origin/branch' that the log message\n> says (using --log):\n> \n> Merge commit 'origin/branch'\n> \n>    * commit 'origin/branch':\n>      Fixed some bug.\n> \n> If I do the same thing from a local tracking branch of origin/branch, it says:\n> \n> Merge branch 'branch'\n> \n>    * branch:\n>      Fixed some bug.\n> \n> Is it expected that it say \"commit\" instead of \"branch\" when the\n> branch is not a local tracking branch? I sometimes merge from remote\n> branches when I don't need to do anything with that branch locally\n> (e.g. I already did the work on another computer and I'm just merging\n> the result into my test machine before I push to the shared server).\n\nI think doing a \"git merge origin/master\" is perfectly normal for some\nworkflows. For example:\n\n  $ git fetch origin ;# grab it\n  $ gitk origin/master...master ;# check if it is good to merge\n  $ git merge origin/master ;# and merge it\n\nThe final step _could_ be a pull, but there is no point in repeating the\nfetch (which might be costly).\n\nThere is already code in fmt-merge-msg to handle remote branches; it\nlooks like we just need to signal that code the same way \"git fetch\"\nwould. Maybe something like the patch below (which is really just a\ncut-and-paste of the code directly above it to special-case real\nbranches).\n\nIt gives a sensible \"Merge\" line but you end up with\n\n  * remote branch 'origin/master':\n    ...\n\ninstead of\n\n  * origin/master:\n    ...\n\nSo it probably requires some deeper digging into what git-fetch is\ndoing, and to emulate that (I am pretty ignorant of this part of the\ncode).\n\n---\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex 0b58e5e..a74a4d0 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -378,6 +378,17 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \t\tgoto cleanup;\n \t}\n \n+\tstrbuf_setlen(&buf, 0);\n+\tstrbuf_addstr(&buf, \"refs/remotes/\");\n+\tstrbuf_addstr(&buf, remote);\n+\tresolve_ref(buf.buf, branch_head, 0, 0);\n+\n+\tif (!hashcmp(remote_head->sha1, branch_head)) {\n+\t\tstrbuf_addf(msg, \"%s\\t\\tremote branch '%s'\\n\",\n+\t\t\t\tsha1_to_hex(branch_head), remote);\n+\t\tgoto cleanup;\n+\t}\n+\n \t/* See if remote matches <name>^^^.. or <name>~<number> */\n \tfor (len = 0, ptr = remote + strlen(remote);\n \t     remote < ptr && ptr[-1] == '^';\n"},{"id":"114479","messageId":"loom.20090522T172429-73@post.gmane.org","threadId":"19435","inReplyTo":"20090522074927.GB1409@coredump.intra.peff.net","subject":"Re: git merge remote branch says \"Merge commit ...\"?","fromName":"Eric Raible","fromEmail":"raible@gmail.com","sentAt":"2009-05-22T17:29:41Z","receivedAt":"2009-05-22T17:29:41Z","isPatch":false,"sender":{"key":"raible@gmail.com","avatar":null},"body":"Jeff King <peff <at> peff.net> writes:\n\n> I think doing a \"git merge origin/master\" is perfectly normal for some\n> workflows. For example:\n> \n>   $ git fetch origin ;# grab it\n>   $ gitk origin/master...master ;# check if it is good to merge\n>   $ git merge origin/master ;# and merge it\n> \n> The final step _could_ be a pull, but there is no point in repeating the\n> fetch (which might be costly).\n\nMy understanding is that if the objects already exist\nlocally then this is not going to be costly at all.\nThe negotiation of what is needed is cheap, isn't it?\n\n- Eric\n"},{"id":"114481","messageId":"20090522175401.GB11640@coredump.intra.peff.net","threadId":"19435","inReplyTo":"loom.20090522T172429-73@post.gmane.org","subject":"Re: git merge remote branch says \"Merge commit ...\"?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-22T17:54:01Z","receivedAt":"2009-05-22T17:54:01Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, May 22, 2009 at 05:29:41PM +0000, Eric Raible wrote:\n\n> Jeff King <peff <at> peff.net> writes:\n> \n> > I think doing a \"git merge origin/master\" is perfectly normal for some\n> > workflows. For example:\n> > \n> >   $ git fetch origin ;# grab it\n> >   $ gitk origin/master...master ;# check if it is good to merge\n> >   $ git merge origin/master ;# and merge it\n> > \n> > The final step _could_ be a pull, but there is no point in repeating the\n> > fetch (which might be costly).\n> \n> My understanding is that if the objects already exist\n> locally then this is not going to be costly at all.\n> The negotiation of what is needed is cheap, isn't it?\n\nNo, it is not terribly expensive. But you do have to talk to the server,\nwhich may mean making an ssh connection, or the server may be overloaded\nand slow. So it can take a few seconds instead of a few microseconds.\n\nThere is actually another reason not to pull, though: you just inspected\nwhat is in origin/master, so that is what you are expecting to merge.\nIf there is new stuff on the remote, you probably don't want to merge it\nwithout similarly inspecting it.\n\n-Peff\n"},{"id":"114483","messageId":"loom.20090522T175633-762@post.gmane.org","threadId":"19435","inReplyTo":"20090522175401.GB11640@coredump.intra.peff.net","subject":"Re: git merge remote branch says","fromName":"Eric Raible","fromEmail":"raible@gmail.com","sentAt":"2009-05-22T18:08:41Z","receivedAt":"2009-05-22T18:08:41Z","isPatch":false,"sender":{"key":"raible@gmail.com","avatar":null},"body":"Jeff King <peff <at> peff.net> writes:\n\n> On Fri, May 22, 2009 at 05:29:41PM +0000, Eric Raible wrote:\n> \n> > Jeff King <peff <at> peff.net> writes:\n> > \n> > > I think doing a \"git merge origin/master\" is perfectly normal for some\n> > > workflows. For example:\n> > > \n> > >   $ git fetch origin ;# grab it\n> > >   $ gitk origin/master...master ;# check if it is good to merge\n> > >   $ git merge origin/master ;# and merge it\n> > > \n> > > The final step _could_ be a pull, but there is no point in repeating the\n> > > fetch (which might be costly).\n> > \n> > My understanding is that if the objects already exist\n> > locally then this is not going to be costly at all.\n> > The negotiation of what is needed is cheap, isn't it?\n> \n> No, it is not terribly expensive. But you do have to talk to the server,\n> which may mean making an ssh connection, or the server may be overloaded\n> and slow. So it can take a few seconds instead of a few microseconds.\n> \n> There is actually another reason not to pull, though: you just inspected\n> what is in origin/master, so that is what you are expecting to merge.\n> If there is new stuff on the remote, you probably don't want to merge it\n> without similarly inspecting it.\n> \n> -Peff\n\nI wasn't trying to argue that a pull would be a good idea, but more\nthat it's not that expensive because of the content-addressable\nnature of git's object store.\n\nAnd saying that is \"might be costly\" could be misleading to people\nwho haven't groked how a commit is a commit is a commit.\n\n- Eric\n"},{"id":"114484","messageId":"20090522181023.GA11913@coredump.intra.peff.net","threadId":"19435","inReplyTo":"loom.20090522T175633-762@post.gmane.org","subject":"Re: git merge remote branch says","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-22T18:10:23Z","receivedAt":"2009-05-22T18:10:23Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, May 22, 2009 at 06:08:41PM +0000, Eric Raible wrote:\n\n> I wasn't trying to argue that a pull would be a good idea, but more\n> that it's not that expensive because of the content-addressable\n> nature of git's object store.\n> \n> And saying that is \"might be costly\" could be misleading to people\n> who haven't groked how a commit is a commit is a commit.\n\nOK, then I agree with you. My \"costly\" was just \"I don't want to touch\nthe network if I don't have to\".\n\n-Peff\n"},{"id":"114485","messageId":"200905222030.34301.j6t@kdbg.org","threadId":"19435","inReplyTo":"20090522175401.GB11640@coredump.intra.peff.net","subject":"Re: git merge remote branch says \"Merge commit ...\"?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2009-05-22T18:30:34Z","receivedAt":"2009-05-22T18:30:34Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Freitag, 22. Mai 2009, Jeff King wrote:\n> No, it is not terribly expensive. But you do have to talk to the server,\n> which may mean making an ssh connection, or the server may be overloaded\n> and slow. So it can take a few seconds instead of a few microseconds.\n\nIt's certainly doable without a remote connection with some digging in the \nconfiguration.\n\nGit-gui has some magic to find out the remote when you request to merge a \nremote tracking branch. That is, even though you clickety-click through to do \nthe equivalent of 'git merge origin/master', it comes up with a merge message \nthat is the same as if you had said 'git pull origin master' on the command \nline. It doesn't need a connection to do that.\n\n-- Hannes\n"},{"id":"114504","messageId":"20090523091711.GB20416@coredump.intra.peff.net","threadId":"19435","inReplyTo":"200905222030.34301.j6t@kdbg.org","subject":"Re: git merge remote branch says \"Merge commit ...\"?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-23T09:17:12Z","receivedAt":"2009-05-23T09:17:12Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, May 22, 2009 at 08:30:34PM +0200, Johannes Sixt wrote:\n\n> On Freitag, 22. Mai 2009, Jeff King wrote:\n> > No, it is not terribly expensive. But you do have to talk to the server,\n> > which may mean making an ssh connection, or the server may be overloaded\n> > and slow. So it can take a few seconds instead of a few microseconds.\n> \n> It's certainly doable without a remote connection with some digging in the \n> configuration.\n\nEr, I think we have gotten a bit off track.\n\nYes, it's clearly possible to pretend you fetched but not actually do so\nwhen doing \"git merge origin/master\" (and the patch I posted does\nsomething close, but doesn't fill in the actual remote name; you just\nget \"remote branch origin/master\").\n\nAll the other part of this thread was just me claiming that:\n\n  git fetch origin\n  git log origin...\n  git merge origin\n\nIs a totally valid workflow, and that the answer should not be \"those\npeople should just run pull\".\n\n> Git-gui has some magic to find out the remote when you request to merge a \n> remote tracking branch. That is, even though you clickety-click through to do \n> the equivalent of 'git merge origin/master', it comes up with a merge message \n> that is the same as if you had said 'git pull origin master' on the command \n> line. It doesn't need a connection to do that.\n\nRight. We could probably use similar logic in \"git merge\". I'm not sure\nif it is worth the trouble to end up with \"Merge branch 'master' of\norigin\" instead of \"Merge remote branch 'origin/master'\".\n\n-Peff\n"},{"id":"114506","messageId":"7vljoo2mql.fsf@alter.siamese.dyndns.org","threadId":"19435","inReplyTo":"20090523091711.GB20416@coredump.intra.peff.net","subject":"Re: git merge remote branch says \"Merge commit ...\"?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-23T09:26:58Z","receivedAt":"2009-05-23T09:26:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Right. We could probably use similar logic in \"git merge\". I'm not sure\n> if it is worth the trouble to end up with \"Merge branch 'master' of\n> origin\" instead of \"Merge remote branch 'origin/master'\".\n\nI do not think it is worth doing that to lose information, either.\n"},{"id":"114645","messageId":"20090525094452.GC22382@coredump.intra.peff.net","threadId":"19435","inReplyTo":"7vljoo2mql.fsf@alter.siamese.dyndns.org","subject":"Re: git merge remote branch says \"Merge commit ...\"?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-25T09:44:52Z","receivedAt":"2009-05-25T09:44:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 23, 2009 at 02:26:58AM -0700, Junio C Hamano wrote:\n\n> > Right. We could probably use similar logic in \"git merge\". I'm not sure\n> > if it is worth the trouble to end up with \"Merge branch 'master' of\n> > origin\" instead of \"Merge remote branch 'origin/master'\".\n> \n> I do not think it is worth doing that to lose information, either.\n\nSo would you be in favor of this patch?\n\n-- >8 --\nSubject: [PATCH] merge: indicate remote tracking branches in merge message\n\nPreviously when merging directly from a local tracking\nbranch like:\n\n  git merge origin/master\n\nThe merge message said:\n\n   Merge commit 'origin/master'\n\n     * commit 'origin/master':\n       ...\n\nInstead, let's be more explicit about what we are merging:\n\n   Merge remote branch 'origin/master'\n\n     * origin/master:\n       ...\n\nWe accomplish this by recognizing remote tracking branches\nin git-merge when we build the simulated FETCH_HEAD output\nthat we feed to fmt-merge-msg.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis is not quite identical to the one I posted before; it adds the\nmagic \"of .\" at the end of the line, which matches how regular\nnon-remote branches are handled.\n\n builtin-merge.c |   11 +++++++++++\n 1 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-merge.c b/builtin-merge.c\nindex 0b58e5e..b6f60e9 100644\n--- a/builtin-merge.c\n+++ b/builtin-merge.c\n@@ -378,6 +378,17 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \t\tgoto cleanup;\n \t}\n \n+\tstrbuf_setlen(&buf, 0);\n+\tstrbuf_addstr(&buf, \"refs/remotes/\");\n+\tstrbuf_addstr(&buf, remote);\n+\tresolve_ref(buf.buf, branch_head, 0, 0);\n+\n+\tif (!hashcmp(remote_head->sha1, branch_head)) {\n+\t\tstrbuf_addf(msg, \"%s\\t\\tremote branch '%s' of .\\n\",\n+\t\t\t\tsha1_to_hex(branch_head), remote);\n+\t\tgoto cleanup;\n+\t}\n+\n \t/* See if remote matches <name>^^^.. or <name>~<number> */\n \tfor (len = 0, ptr = remote + strlen(remote);\n \t     remote < ptr && ptr[-1] == '^';\n-- \n1.6.3.1.250.g01b8b.dirty\n"}]}