远程追踪分支和远程分支之间有什么区别? [英] What is the difference between a remote tracking branch, and a branch on a remote?

查看:84
本文介绍了远程追踪分支和远程分支之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来,我可以从远程存储库的分支中,或者从我正在使用的分支中获取分支。如果是这样,那么远程跟踪分支的目的是什么?



仅仅是为了检查分支并看看它是什么样子?看起来,远程追踪分支就像是远程分支的镜像。

供参考:我对git相当陌生,但已阅读并重新阅读很多教程,但我仍然没有更清楚这一点!



谢谢!

解决方案远程分支和远程跟踪分支都用于指代分支形式 refs / remotes /< remote-name> /< branch-name> ,例如报告作为 origin / master 。 (请注意,这有时与追踪远程分支的分支概念混淆,例如,您的主分支与原始/主分支相关联。术语不幸,但我们确实存在。)

远程追踪分支的目的是记住远程仓库中分支的最后一个已知位置。为了使 git pull 起作用,这是必需的;它从远程分支(原始主分支)获取,将其存储在远程跟踪分支( origin / master )中,然后在本地进行合并。提交只能在本地创建,合并只能在工作树中完成,所以这是完全必要的!



远程跟踪分支也很有用,正如您提到的,用于检查远程存储库中正在发生的事情。默认情况下,远程分支的所有都有远程分支,因此您可以轻松使用 git remote update [--prune]< remote> git fetch< remote> 来更新它们,然后检查它们并随意播放它们。请注意,除了检查它们外,你还可以做其他的事情 - 你可以对它们进行比较( git diff origin / master ),找出你不需要的提交源( git log master..origin / master )或其他你喜欢的东西。由于所有历史考试都是本地的,所以远程分支必须在那里供您使用。



由于 git push 会影响远程分支,它自然会更新您的远程跟踪分支;改变起源的主人并不是很聪明,然后假装它仍然处于旧的位置,直到你找到了!但它实际上并不依赖于远程跟踪分支。 (如果您将 push.default 设置为跟踪,它将 使用您的跟踪配置(例如主跟踪源的主控)来决定推送内容。它仍然实际上不依赖于远程跟踪分支。)


It seems that I can pull from, or push to, a branch on a remote repository, from/to the branch that I am working on. If so, then what is the purpose of a remote tracking branch?

Is it solely for the purpose of checking out the branch and seeing what it looks like? It appears that a remote tracking branch is like a mirror to a branch on a remote.

FYI: I'm fairly new to git, but have read and re-read many tutorials, but I am still no more clear on this point!

Thanks!

解决方案

You're right - remote branches do indeed mirror branches in the remote repository.

Remote branch and remote tracking branch both are used to refer to a branch of the form refs/remotes/<remote-name>/<branch-name>, reported e.g. as origin/master. (Note that this is sometimes confused with the notion of a branch which is tracking a remote branch, e.g. your master branch is associated with origin/master. The terminology is unfortunate, but there we are.)

The purpose of a remote tracking branch is to remember the last known position of the branch in the remote repository. This is necessary in order for git pull to work; it fetches from the branch on the remote (origin's master branch), stores that in the remote tracking branch (origin/master), and then merges that locally. Commits can only be created locally, and merges can only be done in a work tree, so this is completely essential!

The remote tracking branch is also useful, as you mention, for examination of what's going on in the remote repository. By default there are remote branches for all of the remote's branches, so you can easily use git remote update [--prune] <remote> or git fetch <remote> to update them, and then check them out and play with them as you like. Note that you can do things besides check them out - you can diff against them (git diff origin/master), find out what commits origin has that you don't (git log master..origin/master), or anything else you like. Since all examinations of history are local, the remote branch has to be there for you to use.

Since git push affects branches in the remote, it naturally updates your remote tracking branches; it wouldn't be very intelligent to change origin's master then pretend it was still in the old position until you fetched! But it doesn't actually depend on the remote tracking branches. (If you set push.default to tracking, it will use your tracking configuration, e.g. master tracking origin's master, to decide what to push. But it still doesn't actually depend on the remote tracking branch.)

这篇关于远程追踪分支和远程分支之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆