【问题标题】:Git Merge with and without slash [duplicate]带有和不带有斜杠的 Git Merge [重复]
【发布时间】:2017-03-13 15:00:26
【问题描述】:

我有一个关于将您的主/开发分支合并回 git 中的功能/工作分支的问题。有人可以解释以下命令的区别(如果有的话)。我的分支已从开发分支出来,我想用最新的开发更改对其进行更新。

git merge origin development
git merge origin/development

【问题讨论】:

标签: git merge git-merge


【解决方案1】:

来自git-merge manual

git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
  [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
  [--[no-]allow-unrelated-histories]
  [--[no-]rerere-autoupdate] [-m <msg>] [<commit>…​]

&lt;commit&gt;…
提交,通常是其他分支负责人,合并到我们的分支中。

指定多个提交将创建包含两个以上的合并 父母(亲切地称为章鱼合并)。


git merge origin development

这会将origindevelopment 指定的两个提交(在本例中为分支的名称1)合并到您当前的分支中。

o--o     origin
    \
o--o \   development
    \ |
     \|
o--o--o  your-branch

这可能不是你想要的(我想你甚至没有一个名为 origin 的分支)。

(1) 除非您有一个名为origin 的遥控器(这很可能),否则origin 将被解释为远程引用origin/HEAD


git merge origin/development

这会将origin/development(即remote reference)指定的单个提交合并到您当前的分支中。

o--o     origin/development
    \
     \
o--o--o  your-branch

【讨论】:

  • 虽然这似乎准确地反映了文档所说的内容,但观察到的行为是不同的。没有origin 分支(但有一个origin 远程)我可以做git merge origin 并且它确实not 出错(如果上面的解释是完整的)。我对此还没有解释,只有观察到的行为。我认为这意味着 git 有一些将远程名称解释为参考的定义方式
  • 答案出现在问题的 cmets 中:origin 作为参考显然意味着 origin/HEAD
猜你喜欢
  • 2019-07-18
  • 2012-12-14
  • 2018-11-23
  • 1970-01-01
  • 2015-07-07
  • 2017-06-15
  • 2015-06-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多