为什么从非master分支`git pull origin master:master`会导致分支rebase?

问题描述 投票:0回答:1

我在分支

master
并且做
git log

commit 9937b91089895fac45a39a3bda2935e19eb42554 (HEAD -> master, origin/master, origin/HEAD)
...

git status
打印

On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/orig/

nothing added to commit but untracked files present (use "git add" to track)

git branch
打印

  foo
* master

打印的 I

git checkout foo

Switched to branch 'foo'
Your branch is up to date with 'origin/foo'.
...

git status
打印

On branch foo
Your branch is up to date with 'origin/foo'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/orig/

nothing added to commit but untracked files present (use "git add" to track)

git branch
打印

* foo
  master

我做

git pull origin master:master
,打印

Auto-merging .config/Packages.props
CONFLICT (content): Merge conflict in .config/Packages.props
Auto-merging .corext/corext.config
error: could not apply 2fda5e13a117... Initial commit
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Recorded preimage for '.config/Packages.props'
Could not apply 2fda5e13a117... Initial commit

git status
打印

interactive rebase in progress; onto 9937b9108989
Last command done (1 command done):
   pick 2fda5e13a117 Initial commit
No commands remaining.
You are currently rebasing branch 'foo' on '9937b9108989'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
        both modified:   .config/Packages.props

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/Services/AZSM/Test/AzSM.SpanningTests/orig/

git branch
打印

* (no branch, rebasing foo)
  master

然后我执行

git rebase --abort
git checkout master
git log
打印

commit 9937b91089895fac45a39a3bda2935e19eb42554 (HEAD -> master, origin/master, origin/HEAD)
...

表明

master
没有任何更改被拉入 master(也许没有任何更改)。


我认为从

git pull origin master:master
分支运行
foo
相当于

git checkout master
git pull origin master
git checkout foo

但似乎并不是因为

git pull origin master:master
似乎变基了
foo

git version-control rebase git-pull git-fetch
1个回答
0
投票

我认为从 foo 分支运行

git pull origin master:master
相当于...

事实并非如此。

git pull
基本上是
git fetch
后跟
git merge
git rebase

更准确地说,git pull 使用给定的参数运行 git fetch,然后根据配置选项或命令行标志,将调用 git rebase 或 git merge 来协调分歧的分支。

当您运行

git pull origin master:master
时,您基本上是要求 Git 检索远程
master
上的最后更改,并将它们存储到相应的跟踪分支 origin/master
 中,而不是合并/变基到您的 
上。 master
分支。合并/变基部分发生在当前签出的分支上,在您的情况下
foo
当您执行 

git pull

时,它会变基而不是合并,可能是因为您启用了

pull.rebase
 配置,或者 
branch.foo.rebase
 设置为 true。

© www.soinside.com 2019 - 2024. All rights reserved.