簡體   English   中英

無法通過git拉碼拉碼

[英]Not able to pull the code through git pull

我的遠程 GitHub 存儲庫中有兩個以下分支:

master
test-branch

我做了git pull入我的測試目錄,但我沒有看到任何代碼拉入我的本地目錄。 此外,當我執行git branch時,我在這里看不到任何本地分支列表。 不知道為什么? 但是一旦我執行git branch -a ,請參閱下面以紅色顯示的遠程分支:

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

當我執行特定的分支拉取,即git pull origin test-branch時,我看到代碼被拉到我的測試目錄中,但是當我執行git branch時,我看到以下列表:

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

當我提取測試分支代碼時,不知道為什么它在這里顯示 master 。 另外我怎么能看到這個master指向哪個遠程分支?

當您執行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. 將本地分支設置為origin/test-branch

來自 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.

所以這基本上意味着如果你的遠程分支被稱為origin/test-branch它將調用你本地創建的分支test-branch

顯示跟蹤了哪些分支

git status

如果它正在跟蹤,將在第二行顯示它正在跟蹤的遠程

git branch -vv

將向您顯示本地分支機構的列表以及他們正在跟蹤的遠程


查看此stackoverflow 答案以獲得更詳細的答案。

默認情況下, git pull origin xyz運行git fetch origin xyz然后git merge FETCH_HEAD 需要注意的是,指定的遠程分支並沒有被檢出,而是集成到本地分支中。

它顯示* master因為您實際上沒有通過運行git pull origin 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM