Git 带斜线和不带斜线合并

Git Merge with and without slash

我有一个关于将您的 master/development 分支合并回 git 中的 feature/working 分支的问题。有人可以解释一下以下命令的区别(如果有的话)。我的分支已经从开发分支出来,我想用最新的开发更改来更新它。

git merge origin development
git merge origin/development

来自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>…​]

<commit>…
Commits, usually other branch heads, to merge into our branch.

Specifying more than one commit will create a merge with more than two parents (affectionately called an Octopus merge).


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