我有一个目录列表,我想运行git pull
其中一些可能是空的。
当我在其上运行git pull
时,我会收到此错误:
Your configuration specifies to merge with the ref 'master'
from the remote, but no such ref was fetched.
和1
如果任何命令失败,我都会退出脚本。
是否可以检测到由于此错误是否失败?或其他任何可以在空存储库上出现错误的拉动方法?
编辑:.git/config
git:(master) cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = <git repo url>
[branch "master"]
remote = origin
merge = refs/heads/master
这是从此处获取的
在路径,
上克隆一个空存货- 保持在〜/git/Onefile 一个非bare git repo,其中包含一个无害的
文件,例如.gitignore。(或者,创建这样的回购
动态。) - (cd〜/git/onefile; git push 路径 master)
- git clone -o name 路径
换句话说,不要试图克隆空存储库,而是在创建它之后,将其推向一个简单的存储库,其中包含一个无害的文件。然后它不再为空,可以克隆。
您可以在"远程参考"存在上对其进行测试。例如,主参考在初始化后尚不存在,因此在Windows批处理脚本中,这将是这样的:
git ls-remote -h --exit-code myrepo master > nul && (
git pull myrepo master
)