浅克隆无法获取新的提交/分支?

时间:2019-05-16 22:39:09

标签: git git-clone git-checkout

我有这个:

git clone --depth=1 <repo> app
cd app
git fetch origin
git checkout a119b1076dd45a88a3609c4f7893ef3d82f9a4ee

但它说:

fatal: reference is not a tree: a119b1076dd45a88a3609c4f7893ef3d82f9a4ee

如果我使用分支的名称:

 git checkout me/work

我得到:

error: pathspec 'me/work' did not match any file(s) known to git.

是因为我做了一个浅表克隆吗?对我来说没有多大意义。提交位于远程上,至少具有该名称的分支/提交位于远程上。

更新:

所以我在--all上添加了git fetch --all,然后运行git branch -vv --all,我看到了:

* master                4761f83 [origin/master] timeline event update date should not be the review date.  Every time it is inserted or updated the update date should be the current utc date
  remotes/origin/HEAD   -> origin/master
  remotes/origin/master 4761f83 timeline event update date should not be the review date.  Every time it is inserted or updated the update date should be the current utc date

因此该分支不在那个列表中,如果这可以帮助某人帮助我。

4 个答案:

答案 0 :(得分:2)

在进行浅层克隆时,您可能需要指定要提取的分支:

git clone --depth=1 --branch=me/work <repo> app

答案 1 :(得分:2)

我认为,如果您进行浅层克隆,这种方法会起作用

git fetch origin me/work
git checkout -b temp FETCH_HEAD

答案 2 :(得分:2)

正如--depth的文档所述,

  

除非给出--single-branch,否则--no-single-branch就是

所以如果你想

  

获取所有分支机构提示附近的历史记录

为您的克隆提供--no-single-branch,或者一次性校正以获取自身信息,

git fetch --depth=1 origin +refs/heads/*:refs/remotes/origin/*

或追溯关闭单分支设置

git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*

然后是git fetch

答案 3 :(得分:2)

A shallow clone is also, by default, a single-branch clone

  

-深度
  创建一个浅表克隆,其历史记录被截断为指定的提交数。表示--single-branch,除非...

单分支克隆就是它所说的:仅从上游复制一个分支的克隆。 (底层机制是通过默认的fetch refspecs,因此,您可以通过提供refspecs临时为一次获取​​而覆盖它。)

如果要浅层克隆复制多个分支,则必须将其转换为非单分支克隆,或以非单分支克隆开始。首先,请继续阅读引用的句子的其余部分。要将现有的单分支克隆更改为两个,三个或全分支克隆,请参见How do I "undo" a --single-branch clone?

相关问题