Py学习  »  Git

无法通过git pull提取代码

emilly • 2 年前 • 602 次点击  

我的远程GitHub存储库中有以下两个分支:

master
test-branch

我做的 git pull 在我的测试目录中,但我在本地目录中没有看到任何代码。当我这么做的时候 git branch 我在这里没有看到任何本地分支机构的列表。不知道为什么?但一旦我做到了 git branch -a ,请参见以下以红色显示的远程分支:

 remotes/origin/master
 remotes/origin/test-branch

当我做特定的分支拉动时。 git pull origin test-branch 我看到代码被拉到了我的测试目录中,但当我这样做时 吉特分行 我看到下面的清单:

* master
  remotes/origin/test-branch [displayed in red]

不知道为什么在我提取测试分支代码时,它会在这里显示master。还有,我怎样才能看到这个主机指向哪个远程分支?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129231
 
602 次点击  
文章 [ 2 ]  |  最新文章 2 年前
Matt
Reply   •   1 楼
Matt    3 年前

默认情况下, git pull origin xyz git fetch origin xyz 然后 git merge FETCH_HEAD 。请务必注意,指定的远程分支是 未签出,但已整合 进入当地的分支机构。

它显示 * master 因为你实际上并没有通过运行 git拉原点xyz .然而,分支机构的变化 xyz 都融入了当地的 master 自获取后执行合并以来的分支。可能您想先切换到所需的分支( git checkout xyz )然后拉动这些变化( git pull ).

你可以用 git branch -a -vv 要显示远程和本地分支,包括跟踪信息以及当前签出的分支,请执行以下操作:

* xyz                   b7b2f7c [origin/xyz] Commit Message A
  main                  8c4124b [origin/main] Commit Message B
  remotes/origin/HEAD   -> origin/main
  remotes/origin/xyz    b7b2f7c Commit Message A
  remotes/origin/main   8c4124b Commit Message B
V-Mann_Nick
Reply   •   2 楼
V-Mann_Nick    3 年前

当你这么做的时候 git pull origin test-branch 它实际上会把变化从 origin 遥远的 master 分支并将它们合并到当前签出的分支中。

本地签出远程分支并设置跟踪

git fetch
git checkout --track origin/test-branch

这将基本上实现以下功能:

  1. git fetch 将更新到远程
  2. 创建一个名为 test-branch
  3. 安装程序 origin/test-branch 作为远程跟踪分支
  4. 将本地分支设置为 起源/测试分支

从git手册:

-t, --track
When creating a new branch, set up "upstream" configuration. See "--track" in git-branch(1) for details.

If no -b option is given, the name of the new branch will be derived from the remote-tracking branch, by looking at the local part of the refspec configured for the corresponding remote, and then stripping the
initial part up to the "*". This would tell us to use hack as the local branch when branching off of origin/hack (or remotes/origin/hack, or even refs/remotes/origin/hack). If the given name has no slash, or the
above guessing results in an empty name, the guessing is aborted. You can explicitly give a name with -b in such a case.

这基本上意味着如果你的远程分支被调用 起源/测试分支 它将调用本地创建的分支 测试分支 .

显示跟踪的分支的步骤

git status

将在第二行显示它正在跟踪的远程设备

git branch -vv

将向您显示本地分支的列表,以及它们正在跟踪的远程分支


看看这个 stackoverflow answer 想知道更详细的答案。