Ramifications of forgetting slash in “git merge origin/branch”

前端 未结 1 1578
情歌与酒
情歌与酒 2020-12-10 20:02

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 comm

相关标签:
1条回答
  • 2020-12-10 20:18

    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
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题