git - 在空存储库上运行 git pull 不会出现错误

标签 git

我有一个要运行 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

要在路径克隆空存储库,

  1. ~/git/onefile 保留一个包含一个无害文件的非裸 git 存储库
    文件,例如 .gitignore。 (或者,创建这样一个存储库
    动态地。)
  2. (cd ~/git/onefile; git push 路径 master)
  3. git clone -o 名称 路径

换句话说,不要尝试克隆空存储库,而是在创建它之后,向其推送一个包含一个无害文件的简单存储库。那么它就不再是空的,可以被克隆了。

关于git - 在空存储库上运行 git pull 不会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13157417/

相关文章:

Git merge 显示 'rename/deleted' 在两个分支中真正重命名的文件

git - 你能克隆 GitLab 片段吗?

git - 撤消 "Reverting a pull request"

git - 更改 git 存储库中标签的命名约定?

git - 如何将最后一次提交 rebase (压缩)到 master 并更改提交消息

git 克隆显示 "Initialized empty Git repository in xxxxxxxxx(my directory)"

Git 管道 - 快速找出目录中是否有未暂存的文件

git branch -f 和 git checkout 一步到位

git - Azure Pipeline,无法提示,因为终端提示已被禁用

git - 我怎样才能在 Maven 中执行 git pull?