Joh*_*pel 190 git git-remote
我想我正在理解git的基本概念.
我已经设置并克隆了一个远程存储库.我还创建了一个服务器端空存储库,并将我的本地存储库链接到它.
我的问题是我不明白之间的区别:
据我所知,master是一个本地分支,而remotes/origin/master是一个远程分支.
但究竟什么是起源/主人?
lar*_*sks 208
获取远程存储库的克隆并运行git branch -a
(以显示git知道的所有分支).它可能看起来像这样:
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
Run Code Online (Sandbox Code Playgroud)
这master
是本地存储库中的一个分支. remotes/origin/master
是名为master
远程命名的分支origin
.您也可以将其origin/master
称为:
git diff origin/master..master
Run Code Online (Sandbox Code Playgroud)
您也可以将其称为remotes/origin/master
:
git diff remotes/origin/master..master
Run Code Online (Sandbox Code Playgroud)
这只是引用同一事物的两种不同方式(顺便说一下,这两个命令都意味着"告诉我远程master
分支和我的master
分支之间的变化" ).
remotes/origin/HEAD
是default branch
远程命名的origin
.这让你简单地说origin
而不是origin/master
.
Eri*_*ulz 105
像我这样的假人的简短回答(从Torek被盗):
tor*_*rek 39
技术上有没有真正带任何"遥控"的东西1使用Git的回购,有一些只是局部的名字应该对应于另一个名字,不同的回购.命名的那些origin/whatever
最初将与您克隆的repo上的那些匹配 - 来自:
git clone ssh://some.where.out.there/some/path/to/repo # or git://some.where...
Run Code Online (Sandbox Code Playgroud)
制作另一个回购的本地副本.在此过程中,它记录了那里的所有分支,以及那些引用的提交,并将这些分支粘贴到名称下的本地仓库中refs/remotes/origin/
.
根据你面前走多久,git fetch
或相当于更新"我的什么some.where.out.there复制",他们可能会改变他们的分支周围,创建新的,并删除部分.当你执行你的git fetch
(或者git pull
真正的fetch加合并)时,你的repo将复制他们的新工作并refs/remotes/origin/<name>
根据需要更改所有条目.正是那个时刻fetch
才使得一切都匹配(好吧,那个,以及初始克隆,以及一些push
基本情况- 当Git有机会检查时 - 但请参见下面的警告).
Git通常将你自己refs/heads/<name>
称为just <name>
,而将远程的那些称为origin/<name>
,这一切都正常,因为很明显哪一个是哪个.有时可能会创建自己的分支名称,使其不明显,但在发生之前不要担心.:-)只要给Git一个最明显的最短名称,它就会从那里开始:origin/master
"我上次检查时主人在那里",并且master
"根据我一直在做的事情,主人在这里的位置" .运行git fetch
以根据需要更新"主人在那里"的Git.
警告:在早于1.8.4的Git版本中,git fetch
有些模式不会更新"主人在那里"(更确切地说,不更新任何远程跟踪分支的模式).跑步git fetch origin
,或者git fetch --all
,甚至只是git fetch
,不更新.跑步git fetch origin master
没有.不幸的是,这种"不更新"模式是由普通触发的git pull
.(这主要是一个小麻烦,并在Git 1.8.4及更高版本中得到修复.)
1嗯,有一件事被称为 "遥远".但那也是本地的!名称origin
是Git称之为"远程"的东西.它基本上只是您在进行克隆时使用的URL的简称.它也是origin
in的origin/master
来源.该名称origin/master
称为远程跟踪分支,有时会缩短为"远程分支",尤其是在较旧或更为非正式的文档中.
MKJ*_*MKJ 11
我会尝试让@ ErichBSchulz的答案对初学者来说更简单:
我认为通过查看文件夹内部可以最好地理解这个 git 斜杠符号.git
。
例如,下面是我的 LibreOffice 源库的 .git 的稍微缩写的树。
\n\n在linux sudo apt-get install tree
中查看这个很有用。
\n在Windows中,我认为该tree
命令可能仍然有效。
向下滚动并查看底部附近的 refs(又名“参考文献”):
\n\n$ tree \n. \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 branches \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 config \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 description \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 FETCH_HEAD \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 gitk.cache \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 HEAD \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 hooks \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 applypatch-msg.sample \n ...\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 info \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 exclude \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 logs \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 HEAD \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 refs \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 heads \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 master \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 remotes \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 origin \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 remotes \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 origin \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 distro \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cib \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 libreoffice-6-0 \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 collabora \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 cp-6.0 \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lhm \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 libreoffice-5-2+backports \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 HEAD \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 libreoffice-6-2 \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 master \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 private \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mst \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 sw_redlinehide_4a \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 objects \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 info \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pack \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pack-b80087dc57e2b3315f449ca0f1aaa91987bf0c5e.idx \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pack-b80087dc57e2b3315f449ca0f1aaa91987bf0c5e.pack \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pack-eb4e6808029e712d8d9c2671accbbd98aaeb9a04.idx \n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pack-eb4e6808029e712d8d9c2671accbbd98aaeb9a04.pack \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ORIG_HEAD \n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 packed-refs \n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 refs \n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 heads \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 master \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 remotes \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 origin \n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 remotes \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 origin \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 distro \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cib \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 libreoffice-6-0 \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 collabora \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 cp-6.0 \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lhm \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 libreoffice-5-2+backports \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 HEAD \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 libreoffice-6-2 \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 master \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 private \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mst \n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 sw_redlinehide_4a \n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tags \n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 libreoffice-6-2-branch-point \n\n32 directories, 45 files\n
Run Code Online (Sandbox Code Playgroud)\n\n如果像这样布局,可能不会那么混乱,但事实并非如此:
\n\nrepositories (i.e. independent trees)\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80local\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80master\n\xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80origin1\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80master\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80origin2\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80master\n
Run Code Online (Sandbox Code Playgroud)\n\n我们有三种基本类型的引用:heads、remotes和tags。
\n\n.git/refs/ Heads保存着我们本地的master。
.git/refs/ remotes可以容纳多个遥控器,尽管目前我们只有origin。
.git/refs/ tags(在别处讨论)。
由此可见,起源是我们唯一的遥远的。它包含origin/master。
\n\n我们发现我们有 2 个HEADS(指向当前分支的指针),一个是本地的,一个是远程的:
\n\n$ cat .git/HEAD # local: HEAD -> master\nref: refs/heads/master\n\n$ cat .git/refs/remotes/origin/HEAD # remote origin: HEAD -> master\nref: refs/remotes/origin/master\n
Run Code Online (Sandbox Code Playgroud)\n\n如果您列出您的分支机构:
\n\n$ git branch -a\n* master\n remotes/origin/HEAD -> origin/master\n remotes/origin/aoo/aw080\n remotes/origin/aoo/trunk\n remotes/origin/distro/capgemini/cg-4.1\n remotes/origin/distro/cib/libreoffice-5-0\n remotes/origin/distro/cib/libreoffice-5-1\n remotes/origin/distro/cib/libreoffice-5-2\n ...\n
Run Code Online (Sandbox Code Playgroud)\n\n接下来,你可能有很多远程跟踪分支,我们在这里做。您知道这些是远程跟踪分支,因为它们的前缀为“ remotes/ ”。此处显示的是名为 origin 的远程。
\n\n所以第二行是origin当前的分支指针。远程/来源:HEAD --指向--> master。这表明在远程存储库中,当前分支是名为master 的分支(不要与名为master的本地分支混淆)。
其余分支在您的 .git/refs/ 树中找不到,但您会在 .git/refs/ 树中找到它们.git/packed-refs
。
当我们git fetch时,我们将更改从远程存储库下载到远程跟踪存储库中。
\n\n当我们git merge时,我们将这个本地远程跟踪存储库中的更改合并到我们的工作本地分支或多个分支中,在本例中合并到我们的主分支中。
\n\n(当我们git pull时,我们在一次操作中完成这两个步骤。)
\n\n值得注意的是,master的这些本地和远程UUID当前指向同一节点(也称为“提交”):
\n\n$ cat refs/heads/master # local master\n1ca409292272632f443733450313de5a82c54a9c\n\n$ cat refs/remotes/origin/master # remote origin master\n1ca409292272632f443733450313de5a82c54a9c\n
Run Code Online (Sandbox Code Playgroud)\n\n因此,我们的本地主机指向与远程主机的原始主机相同的位置:
\n\n[local] master = [remote] origin master\n
Run Code Online (Sandbox Code Playgroud)\n\n最后,我觉得看看也很有用.git/packed-refs
$ cat packed-refs \n# pack-refs with: peeled fully-peeled \n3c1d4742e649fe9c8aed8c2817fe3e1f3364f298 refs/remotes/origin/aoo/aw080\ne87c8b7922e9a73e0abb7f9a7a47c9ac3374a826 refs/remotes/origin/aoo/trunk\nb70fdffb041c12f124dcc0822b61bf3450e53137 refs/remotes/origin/distro/capgemini/cg-4.1\n5dbc3f1754809b9489faaf380b1a4bdbcfbb6205 refs/remotes/origin/distro/cib/libreoffice-5-0\ncfdbc96ca47d68d6785fd21829a8d61f49d6e591 refs/remotes/origin/distro/cib/libreoffice-5-1\n5189c8c47461ef09739086e55512fc6a10245273 refs/remotes/origin/distro/cib/libreoffice-5-2\n3bee5917569ca8e6ee3b086458f5b1a917b88ca1 refs/remotes/origin/distro/cib/libreoffice-5-3\n92fbe703f9ca480d3a2b8610d87e991c729edf77 refs/remotes/origin/distro/cib/libreoffice-5-4\n05c0a5df66cc69d75280f05b804cf82f3387d42b refs/remotes/origin/distro/cib/libreoffice-6-0\n7fe193e759b24b90852e6e327115b77114d7b119 refs/remotes/origin/distro/cib/libreoffice-6-1\n8187f7aa413e7ef7b377eea2b057d336bf256867 refs/remotes/origin/distro/collabora/cd-5.3\n7a6b608591e21ef61dc05cff9fc58da531035755 refs/remotes/origin/distro/collabora/cd-5.3-3.1\n....\n
Run Code Online (Sandbox Code Playgroud)\n\n毫无疑问,这留下的问题多于答案,但我认为它可以开始帮助你回答你自己关于什么是什么的问题。
\n小智 5
一个澄清(以及让我困惑的一点):
“remotes/origin/HEAD 是默认分支”并不正确。
remotes/origin/master 是远程存储库中的默认分支(上次检查时)。HEAD 不是一个分支,它只是指向一个分支。
将 HEAD 视为您的工作区域。当您以这种方式思考时,“git checkout branchname”对于将您的工作区文件更改为特定分支的文件是有意义的。您将分支文件“签出”到您的工作区域。出于所有实际目的,HEAD 是您在工作区域中可见的内容。
$ git remote add origin https://github.com/git/git.git
---您将运行此命令将github项目链接到origin。这里的起源是用户定义的。
您可以通过以下方式重命名$ git remote rename old-name new-name
$ git fetch origin
-将对象和引用从远程存储库下载到本地计算机[来源/主机]。这意味着它将不会影响您的本地master分支,除非您使用合并它们$ git merge origin/master
。记住在运行此命令之前签出需要合并的正确分支
注意:提取的内容表示为远程分支。通过Fetch,您可以先查看更改,然后再将其集成到项目副本中。显示您和遥控器之间的更改$git diff master..origin/master
归档时间: |
|
查看次数: |
105516 次 |
最近记录: |