能够编辑远程分支的本地副本

Ability to edit local copies of remote branches

我很难understanding/verifying下面这行来自Pro Git

It’s important to note that when you do a fetch that brings down new remote-tracking branches, you don’t automatically have local, editable copies of them. In other words, in this case, you don’t have a new serverfix branch — you have only an origin/serverfix pointer that you can’t modify.

我尝试了以下存储库。

git clone git://git.bugseng.com/ppl/ppl.git
cd ppl

我从我的本地机器上删除了文件夹 ppl/src/,并将预先存在的文件夹 ppl/m4/ 复制到 ppl/m4 - Copy 中,以便在本地 modify/edit 这个文件夹有点。

然后,我 运行 git fetch origin 只是为了(我认为)让自己处于上述书中引用的情况。我(当然)没有任何 write 访问此在线存储库的权限。

现在,我可以轻松地完成 git add .git commit 而不会出现任何错误。 git status 的输出是:

:~/ppl$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.

一切如预期。也就是说,我已经能够提交并在本地编辑 b运行ch 。我无法将这与书中的引述相协调,该引述指出我不会拥有它们的本地可编辑副本。

请注意,您引用的短语指的是 serverfix 分支 — 而不是 master

master 的情况下(或远程 HEAD 是什么),当您克隆时,您会自动获得一个本地副本;所以你不需要做一个。

但是如果有任何 other 分支,clone 不会为您制作这些分支的本地副本,而仅仅 fetch 也不会给你他们的本地副本。您可能有 remote-tracking 个分支,例如 origin/someBranch,但如果您想 编辑 someBranch,则必须先创建它。

Pro Git 参考资料说 a git fetch 实际上并没有签出您获取的远程 b运行ch 的本地副本。它只是一个指针,允许 git 在本地知道 b运行ch 存在并允许您检查它。要对此进行测试,请克隆远程存储库的副本。接下来在您的遥控器 fetch-branch-test 上创建一个 b运行ch。 运行 git checkout fetch-branch-test 在您的本地存储库中,您将收到一条错误消息,提示 git 找不到 b运行ch。 运行 git fetch 本地,然后 git branch。您会看到仍然没有 fetch-branch-test 的本地副本。最后,再次 运行 git checkout fetch-branch-test,您会注意到您现在拥有远程 b运行ch 的本地副本。这是因为 git fetch 添加了新远程 b运行ch 的本地指针,但直到 运行 git checkout.[=18 才添加它的本地副本=]