如何将 git "--unshallow" 与 "--single-branch" 克隆一起使用?

how to use git "--unshallow" with a "--single-branch" clone?

我首先浅克隆了一个深度为 1 的 repo。

cd $folder_path
git init
git remote add $my_remote $url_to_repo
git fetch $my_remote $my_branch --depth=1
git reset --hard $my_remote/$my_branch
cd -

然后我尝试通过 运行 两次

来取消本地克隆
if [[ ! -z "$(git rev-parse --is-shallow-repository)" ]]; then
    echo "STILL SHALLOW"
    git fetch $my_remote $my_branch --unshallow 
fi

我得到了"STILL SHALLOW"两次,一步一步还是一样...

$ git rev-parse --is-shallow-repository
--is-shallow-repository
$ git fetch $my_remote $my_branch --unshallow 
remote: Counting objects: 16, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 16 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (16/16), done.
From ssh://my_git_url.git
 * branch              my_branch -> FETCH_HEAD
$ git rev-parse --is-shallow-repository
--is-shallow-repository

那我做错了什么? 如何使用 --unshallow ?

git rev-parse --is-shallow-repository 应该是 return truefalse 所以使用 if [[ ! -z "$(git rev-parse --is-shallow-repository)" ]] 总是被视为 TRUE 因为即使 false(return由命令编辑)不是空字符串。

你的 git 版本似乎不支持 rev-parse --is-shallow-repository 子命令,结果在这种情况下任何标志都会被 returned 作为输出:

$ git rev-parse --repo-is-not-shallow-anymore

$ --repo-is-not-shallow-anymore

由于以下错误,您的回购并不浅,无需采取进一步行动:

fatal: --unshallow on a complete repository does not make sense