【问题标题】:How do I check if a repository is bare?如何检查存储库是否裸露?
【发布时间】:2009-12-02 04:45:18
【问题描述】:

我收到警告

warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch

这是(我认为)遥控器不是裸露的警告。然而,我打算让 remote 裸露,并且该目录(格式为 foo.git)中没有 .git 目录。如何检查它是否裸露?

额外信息:远程仓库在一台电脑上,git 1.5.4.3,本地仓库有git 1.6.3.3。两台机器都是 Ubuntu - 本地的是 Karmic Koala,远程的是旧版本。

【问题讨论】:

  • 刚刚添加了表明存储库是裸存储库的条件
  • $ git rev-parse --is-bare-repository - 信用 jberryman please upvote his answer

标签: git


【解决方案1】:

如何检查它是否裸露?

正如jberrymananswer below(赞成)中提到的,如果您有权访问远程仓库,则可以在其中运行:

git rev-parse --is-bare-repository 

早在commit 493c774, Git 1.5.3(2007 年 9 月)和commit 7ae3df8 就由Matthias Lederhofer (matled) 引入。

当存储库是裸打印“true”,否则为“false”。


你可以使用(来自git config):

 git config --add push.default current

指定默认推送的内容。

或:

 git config --global push.default matching

如果您有很多存储库。

current:将当前分支推送到同名分支。

还要检查警告后是否没有出现类似 SO question 的错误消息。


所以你的目标 repo 可能是一个空的,但是,正如 Sensible Git Refspecs 所说:

当您执行git pullfetch, push 和其他一些操作时,您需要为当前存储库指定refspec
refspec 描述了本地引用和远程引用之间的映射,因此您可以推送(或拉取等)主分支头并将其存储为您的原始分支头。基本上这是一种在 repos 之间映射分支的方式。

另见“concept of bared shared repository in git”。


注意:这比来自Git1.6.3,:

git push”进入当前签出的分支默认会被拒绝。
您可以通过在接收存储库中设置配置变量 receive.denyCurrentBranch 来选择在此类推送时应该发生什么。

但我不认为这是你现在看到的。


如“all about "bare" repos -- what, why, and how to fix a non-bare push”(底部)中所述

要使其成为“真正的”裸仓库,只需删除除.git 之外的所有文件,然后删除mv .git/* .; rmdir .git
最后,编辑名为config 的文件并将bare = false 更改为@ 987654348@.

因此,如果您的目标仓库有一个带有 bare = trueconfig 文件,那么它就是一个裸仓库。

【讨论】:

    【解决方案2】:

    听起来这不是你的问题,但要真正回答你在标题中提出的问题:你可以运行...

    $ git rev-parse --is-bare-repository
    

    ...查询回购是否是裸露的。返回“真”或“假”。

    【讨论】:

    • 谢谢。这正是我所需要的。
    【解决方案3】:

    您收到的消息意味着您的远程存储库是空的(这与裸机无关)。首次推送到远程存储库时,您需要指定要推送的内容:

    git push origin master
    

    这会将您当前的主分支推送到远程存储库。 git push 的后续调用将推送“匹配”分支,即如果远程存储库中有“主”分支,您的本地“主”分支将被推送到它。

    【讨论】:

    • 您也可以说“git push --all”将本地副本中的所有内容推送到远程。 (从 Subversion 转换为 300 多个 git 存储库后,我对这个命令非常熟悉!)
    • 你指的是远程仓库是裸露的,还是我本地仓库的远程分支?
    • 两者都不是,这才是重点。您收到的消息与您的任何存储库 bare 无关。这是关于您的远程存储库是 empty,即其中没有提交,没有分支,什么都没有。
    • 远程存储库以前经常被用作远程存储库(尽管在 1.5.x 下),但本地存储库是新的。这与您的诊断相符吗?
    【解决方案4】:

    试试

     $ git config --get core.bare
    

    【讨论】:

      【解决方案5】:

      打开.get目录下的config文件,查找bare = true

      【讨论】:

        猜你喜欢
        • 2011-09-08
        • 2015-04-02
        • 1970-01-01
        • 1970-01-01
        • 2011-11-08
        • 2014-06-26
        • 1970-01-01
        • 2013-08-25
        • 2015-12-01
        相关资源
        最近更新 更多