“跟踪”的概念是否有不同的含义?在吉特?
我运行 'git Branch -r' 并得到
原点/分支1
原点/分支2
在手册页中,-r 选项将“列出或删除(如果与 -d 一起使用)远程跟踪分支”。因此 origin/branch1 和 origin/branch2 被称为远程跟踪分支。但是,您无法直接提交到远程跟踪分支(将创建一个匿名分支)。远程跟踪分支仅在运行“git fetch”时跟踪远程分支。
这就是语义对我来说有点模糊的地方。如果我那么
git checkout -bbranch1 origin/branch1
我得到以下输出: “分支branch1设置为跟踪来自原点的远程分支branch1。切换到新分支'branch1'”
这是我的问题,尽可能详细地阐明是什么让我困惑...... 由于将branch1设置为从原点跟踪远程分支branch1,因此“branch1”是否被视为远程跟踪分支?如果是这样,这是否与运行“gitbranch-r”时“origin/branch1”已被列为远程跟踪分支的事实相冲突?据我了解,存在本地(主题)分支或远程跟踪分支。运行“git checkout -bbranch1 origin/branch1”时,我是否创建一个本地(主题)分支(我可以在其中添加提交),该分支通过获取方式跟踪远程分支?运行“gitbranch”现在给出:“*branch1”,运行“gitbranch-r”仍然给出“origin/branch1”和“origin/branch2”。我创建了branch1来添加提交并跟踪origin/branch1。哪个被认为是远程跟踪分支,“gitbranch”输出中的“branch1”,还是“gitbranch-r”输出中的“origin/branch1”?
I run 'git branch -r' and get
origin/branch1
origin/branch2
From the man page, the -r option will "list or delete (if used with -d) the remote-tracking branches". So origin/branch1 and origin/branch2 are known as remote-tracking branches. However, you can't commit directly onto a remote-tracking branch (an anonymous branch will be created instead). A remote-tracking branch simply tracks a remote branch when running 'git fetch'.
Here's where the semantics get a little blurry for me. If I then
git checkout -b branch1 origin/branch1
I get the following output:
"Branch branch1 set up to track remote branch branch1 from origin. Switched to a new branch 'branch1'"
Here's my question, put as verbosely as possible to clarify what's confusing me...
By virtue of having branch1 set up to track remote branch branch1 from origin, is 'branch1' thus considered a remote-tracking branch? If so, doesn't this conflict with the fact that 'origin/branch1' was already listed as a remote tracking branch when running 'git branch -r'? From what I understand, there exist either local (topic) branches or remote-tracking branches. When running 'git checkout -b branch1 origin/branch1', am I creating a local (topic) branch (onto which I can add commits) that is tracking a remote branch by way of fetches? Running 'git branch' now gives: '* branch1', and running 'git branch -r' still gives 'origin/branch1' and 'origin/branch2'. I created branch1 to add commits to and to track origin/branch1. Which is considered the remote-tracking branch, 'branch1' from the output of 'git branch', or 'origin/branch1' from the output of 'git branch -r'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个关于一个特别烦人的 git 术语的好问题,尽管该项目似乎正在慢慢修复。
基本上,“track”在表达式 (a) “远程跟踪分支”和 (b) “
branch1
设置为跟踪来自branch1
的远程分支branch1
中的含义非常不同。代码>来源”。下面是一个快速总结:git fetch
更新的分支,因此,git pull< /code>.¹ 您可以将它们视为远程存储库中分支状态的缓存。您可以合并它们,检查它们的历史记录等,但不能直接对它们进行操作。该短语中的“跟踪”意味着远程跟踪分支表示上次更新远程跟踪分支时远程存储库中的分支的状态。
foo
与远程跟踪分支origin/bar
关联起来。这可以实现一些不错的功能,例如当您在分支foo
上时只需键入git pull
即可从origin/bar
获取并合并>。这也是您如何获取有关您的分支相对于远程跟踪分支的状态的有用消息,例如“您的分支foo
比origin/bar
提前了 24 次提交”可以快进”。您被告知您的本地分支正在跟踪已与远程跟踪分支相关联。您还听说过,origin/bar
是foo
的上游。因此,这些追踪/追踪的感觉是完全不同的,遗憾的是,这是一个常见的混乱来源。
然而,第二种含义似乎正在慢慢被弃用 - 例如,
push.default
的可能选项之一曾经是tracking
,但现在已被弃用。选项名称upstream
。因此,直接回答您的问题:
不,
branch1
不是远程跟踪分支。嗯,有点像 - 它正在跟踪(意义 2)一个远程跟踪分支,而后者是通过获取从远程存储库中的分支进行更新的。 (就我个人而言,我尽量避免使用术语“远程分支”,而倾向于使用“远程存储库中的分支”,以防人们认为您指的是远程跟踪分支。)
远程跟踪分支是
origin/branch1
。1 当您成功将
git Push
推送到远程存储库中的相应分支时,它们也会更新。This is a good question about a particularly annoying bit of git terminology, albeit one that the project seems to be slowly fixing.
Basically, "track" means something very different in the expressions (a) "remote-tracking branch" and (b) "
branch1
set up to track remote branchbranch1
fromorigin
". Here's a quick summary:git fetch
, and, consequently,git pull
.¹ You can think of these as like a cache of the state of the branch in the remote repository. You can merge from them, examine their history, etc. but you can't work directly on them. "Track" in this phrase means that the remote-tracking branch represents the state of the branch in the remote repository the last time that remote-tracking branch was updated.foo
with the remote-tracking branchorigin/bar
. This enables nice features like being able to just typegit pull
while you're on branchfoo
in order to fetch and then merge fromorigin/bar
. It's also how you get helpful the messages about the state of your branch relative to the remote-tracking branch, like "Your branchfoo
is 24 commits ahead oforigin/bar
can can be fast-forwarded". You're being told that your local branchis trackinghas been associated with a remote-tracking branch. You also hear this referred to asorigin/bar
being upstream with respect tofoo
.So, these senses of track / tracking are quite different, and sadly it's a common source of confusion.
The second sense seems to be being slowly deprecated, however - for example, one of the possible options for
push.default
used to betracking
, but this is now deprecated in favour of the option nameupstream
.So, to answer your questions directly:
No,
branch1
is not a remote-tracking branch.Well, sort of - it's tracking (sense 2) a remote-tracking branch, and the latter is updated from a branch in the remote repository by fetches. (Personally, I try to avoid the term "remote branch", in favour of "the branch in the remote repository", just in case people think you mean a remote-tracking branch.)
The remote-tracking branch is
origin/branch1
.¹ They're also updated when you make a successful
git push
to the corresponding branch in the remote repository.