簡體   English   中英

如何使 git “看到”一個遠程分支,用於使用 --single-branch 克隆的倉庫?

[英]How to make git “see” a remote branch for a repo that was cloned with --single-branch?

我有一個存儲庫,其中 git 看不到源/主。 它最初是使用“--single-branch stable”選項克隆出來的。 這是一個巨大的存儲庫,現在我也需要使用 origin/master。 我不想重新克隆整個 repo,因為它真的很大,而且需要很多時間。

以下是遙控器:

# git remote -v                                                                                                                                                              
origin  git@gitlab.not_telling.com:group_name/project_name.git (fetch)
origin  git@gitlab.not_telling.com:group_name/project_name.git (push)

這是“git log”的第一行:

commit 7e43bd67a31313ce6f09c79ce27f5a40026bf358 (HEAD -> master, tag: uat_2019-10-25, tag: stable_2019-10-25, origin/stable, stable)

git 已知的本地分支是masterstable git 已知的遠程分支是origin/stable ,但缺少origin/master

如果我嘗試將 stable 重置為 origin/master:

git checkout stable
git reset origin/master --hard
fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

如果我嘗試設置上游:

# git branch --set-upstream-to master origin/master                                                                                                                         
fatal: branch 'origin/master' does not exist

如果我嘗試獲取:

# git checkout master && git fetch -v
Already on 'master'
From gitlab.not_telling.com:group_name/project_name
= [up to date]        stable     -> origin/stable

另外,如果我嘗試使用git branch -a列出所有分支,那么 origin/master 不存在:

* master
  stable
  remotes/origin/stable

我怎樣才能讓 git “知道”起源/主人?

您可以通過編輯您的 .git/config 文件並將 master 添加到遠程“origin”部分來將遠程分支添加到 fetch 列表中:

[remote "origin"]
    url = git@gitlab.not_telling.com:group_name/project_name.git
    fetch = +refs/heads/stable:refs/remotes/origin/stable
    fetch = +refs/heads/master:refs/remotes/origin/master

然后進行抓取:

git fetch origin

現在,origin/master 應該在本地存儲庫中顯示為 ref。 (如果需要,您可能仍需要創建本地主分支)。

暫無
暫無

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

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