5

Per this article, I've tried to get myself in the habit of fetching and merging explicitly when updating my working copy. However, today I made a typo when issuing the command:

$ git fetch origin
$ git merge origin asdf

Note that I used a space instead of a forward slash on the merge command. Because it appeared to have had the desired effect anyway, I didn't notice until I had already pushed that it had added a strangely worded commit to the log:

commit 65f0037bed926c338cb95e7437e7f7f407028d9f
Author: Me <my_email@example.com>
Date:   Mon May 14 09:36:44 2012 -0700

    Merge branch 'asdf', remote-tracking branch 'origin' into asdf

Now I'm wondering if this actually had any negative side effects. It seems like it treated the arguments as two separate branch specs to merge into the current branch, and that "origin" would have implicitly expanded to "origin/asdf" — which is what I actually intended. At that point, I have no idea why it would even permit "Merge branch 'asdf' into asdf" to occur.

Was this just an embarrassing no-op? Or have I introduced a potentially problematic construct into my repository history?

EDIT: Output of git cat-file commit 65f0037b

tree 74ed9ead4b82e4e56bd5656ee10375f8f0fcb60d
parent 3bc2a37031a4a391aa4da64c22e3f55148cd23e2
author Me <my_email@example.com> 1337013404 -0700
committer Me <my_email@example.com> 1337013404 -0700

    Merge branch 'asdf', remote-tracking branch 'origin' into asdf
Zach
  • 356
  • 3
  • 9
  • similar to this? http://stackoverflow.com/questions/2602546/how-do-i-git-fetch-and-git-merge-from-a-remote-tracking-branch-like-git-pu – bluesman May 14 '12 at 19:28
  • Can you do `git cat-file commit 65f0037b`? You may have performed an octopus merge or one of the commits may just have fast-forwarded and you may have got what you wanted with a misleading commit message. It's hard to tel from the commit description. – CB Bailey May 14 '12 at 20:15
  • @Charles Bailey: Unfortunately, about 45 minutes after I asked this question, I decided to err on the side of caution, and hard reset + redo the questionable merge. I realize that may render this question impractical to answer definitively, for which I apologize. However, the answer larsks gave, in conjunction with the fact that I know the default branch was in fact "origin/asdf" leads me to believe that the merge did indeed coincidentally (and awkwardly) accomplish what I had originally intended. – Zach May 14 '12 at 21:26
  • 1
    Unless you've deliberately set your prune time to very short and have gc'ed in the past hour, commit 65f0037b should still exist... not that it's important any more. – CB Bailey May 14 '12 at 21:34
  • I edited it into the question. Not that it's important any more. But I'm curious what it would have told you. – Zach May 14 '12 at 21:56
  • 2
    @Neverender: It tells me that it only has one parent (which I can't otherwise see from the log) which means that it wasn't a true merge, just a regular commit with a misleading commit message. It may be that there was no actual change in the commit or, slightly more worryingly, the parent information was lost. Perhaps your local clone was up to date when you did this. – CB Bailey May 15 '12 at 09:07

1 Answers1

4

Let's start with the man page for the merge command:

   git merge [-n] [--stat] [--no-commit] [--squash]
           [-s <strategy>] [-X <strategy-option>]
           [--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]

So, absent all the options, merge accepts a list of commits. If you're already on branch asdf and you type:

git merge asdf

...this is a no-op: merging a branch with itself means there's nothing to do. If you type this:

git merge origin

Then git will look for the default branch associated with the remote named origin. In the output of branch -a:

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

remotes/origin/HEAD points to the default branch, so:

git merge origin

is equivalent to:

git merge origin/master

So assuming that the default branch on your remote is master, when you typed:

git merge origin asdf

You got:

git merge origin/master

If the default branch was asdf, you got:

git merge origin/asdf
David Cain
  • 16,484
  • 14
  • 65
  • 75
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Does not explain the remote tracking branch – bluesman May 14 '12 at 19:27
  • Yes, I can say for sure that remotes/origin/HEAD did in fact point to origin/asdf in this example. I take this to mean that my original assessment (accidentally getting the desired result + awkward no-op) was accurate. – Zach May 14 '12 at 21:28