Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ramifications of forgetting slash in "git merge origin/branch"

Tags:

git

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 <[email protected]>
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 <[email protected]> 1337013404 -0700
committer Me <[email protected]> 1337013404 -0700

    Merge branch 'asdf', remote-tracking branch 'origin' into asdf
like image 288
Neverender Avatar asked Oct 07 '22 20:10

Neverender


1 Answers

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
like image 95
larsks Avatar answered Oct 12 '22 11:10

larsks