问题描述
正如我所看到的,git - track 和 - set-upstream-to 修改了一个分支所以它成了一个跟踪(或上游)分支。但我无法理解的细微差别在哪里。 - track 记录remote branch tracks local:
$ git checkout foo -b
$ git branch --track origin / retarget
设置追踪本地分支foo的分支源/重定目标。
$ cat .git / config
[branchorigin / retarget]
remote =。
merge = refs / heads / foo
- set -upstream-to 记录本地分支跟踪远程分支:
$ git checkout foo -b
$ git branch --set-upstream-to origin / retarget
设置分支foo以追踪远程分支从原点返回的目标。
$ cat .git / config
[branchfoo]
remote = origin
merge = refs / heads / retarget
这两者有什么区别?我确信跟踪分支是一个简单的概念,在分支中跟踪头部指定分支位置的额外上游指针在远程存储库中。但似乎更复杂?
$ git checkout foo -b
$ git branch --track origin / retarget
前两个命令指示git:
- 创建一个名为 origin / retarget 的本地分支(非常糟糕的想法,因为它是命名为远程跟踪分支,而它实际上是一个简单的本地分支,其名称中包含 / ')
- 开始从当前分支( foo ,另一个本地分支)
- 使新的本地分支跟踪其起始点。 li>
请参阅
- 曲目
当你从一个分支开始创建一个分支时,你会使用跟踪远程跟踪一个。
换句话说,你的第一个例子不是你将如何使用 - track 。
这会更好:
git checkout -b foo --track origin / retarget
至于之间的区别 - track 和 - set-upstream-to :
- set-upstream-to
As I can see, both git --track and --set-upstream-to modify a branch so it becames a tracking (or upstream) branch. But where is a subtle difference I can't comprehend. The --track records "remote branch tracks local":
$ git checkout foo -b $ git branch --track origin/retarget Branch origin/retarget set up to track local branch foo. $ cat .git/config [branch "origin/retarget"] remote = . merge = refs/heads/foo
While --set-upstream-to records "local branch tracks remote branch":
$ git checkout foo -b $ git branch --set-upstream-to origin/retarget Branch foo set up to track remote branch retarget from origin. $ cat .git/config [branch "foo"] remote = origin merge = refs/heads/retarget
What's the difference between this two? I was sure that "tracking branch" is simple concept with additional upstream pointer inside branch that tracks head position of specified branch in remote repository. But seems it's much more complicated?
$ git checkout foo -b $ git branch --track origin/retarget
The first two commands instruct git to:
- create a local branch named "origin/retarget" (very bad idea, as it is named as a remote tracking branch", while it is actually a simple local branch with a '/' in its name)
- starting from the current branch ("foo", another local branch)
- to make that new local branch tracking its starting point.
See git branch
--track
You would use track when you create a branch starting from a remote tracking one.
In other word, your first example isn't how you would use --track.
This would work better:
git checkout -b foo --track origin/retarget
As for the difference between --track and --set-upstream-to:
--set-upstream-to
这篇关于git“ - track”的区别是什么?和“设置 - 上游到”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!