我有一个要运行 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
最佳答案
这取自here
要在路径克隆空存储库,
- 在 ~/git/onefile 保留一个包含一个无害文件的非裸 git 存储库
文件,例如 .gitignore。 (或者,创建这样一个存储库
动态地。) - (cd ~/git/onefile; git push 路径 master)
- git clone -o 名称 路径
换句话说,不要尝试克隆空存储库,而是在创建它之后,向其推送一个包含一个无害文件的简单存储库。那么它就不再是空的,可以被克隆了。
关于git - 在空存储库上运行 git pull 不会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13157417/