git 如何检查存储库是否是空的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1830701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:58:37  来源:igfitidea点击:

How do I check if a repository is bare?

git

提问by Andrew Grimm

I'm getting the warning

我收到警告

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

which is (I think) a warning that remote is not bare. Yet I intended remote to be bare, and the directory (which is in the form foo.git) doesn't have a .git directory in it. How do I check that it is bare?

这是(我认为)远程不是裸露的警告。然而,我打算远程裸机,并且目录(形式为foo.git)中没有 .git 目录。我如何检查它是否裸露?

Extra information: The remote repository is on a computer with git 1.5.4.3, and the local repository has git 1.6.3.3. Both machines are Ubuntu - the local one is Karmic Koala, the remote one is an older version.

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

回答by jberryman

It doesn't sound like that was your problem, but to actually answer the question you asked in the title: you can run...

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

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

...to query if a repo is bare or not. Returns 'true' or 'false'.

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

回答by VonC

How do I check that it is bare?

我如何检查它是否裸露?

As mentioned in the answer below(upvoted) by jberryman, if you have access to the remote repo, you can run in it:

正如提到以下答案(upvoted)由jberryman,如果你有机会到远程回购,你可以在它运行:

git rev-parse --is-bare-repository 

It was introduced as early as commit 493c774, Git 1.5.3(Sept. 2007) and commit 7ae3df8by Matthias Lederhofer (matled).

它早在提交 493c774、Git 1.5.3(2007 年 9 月)和 由Matthias Lederhofer ( )提交的 7ae3df8 中引入matled

When the repository is bare print "true", otherwise "false".

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



You could use (from git config):

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

 git config --add push.default current

to specify what you want to push by default.

指定默认情况下要推送的内容。

or:

或者:

 git config --global push.default matching

if you have many repositories.

如果你有很多存储库。

current: push the current branch to a branch of the same name.

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

Check also if the warning was not followed by an error message like in this SO question.

还要检查警告后面是否没有像这个SO question那样的错误消息。



So your destination repo may be a bare one, but, as said in Sensible Git Refspecs:

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

When you do a git pull, fetch,pushand some others you need to specify a refspecfor the current repository.
A refspecdescribes the mapping between the local reference and the remote one, so you can push (or pull etc) the master branch head and store it as your origin branch head. Basically it's a way of mapping branches between repos.

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

See also "concept of bared shared repository in git".

另请参阅“ git 中裸露共享存储库的概念”。



Note: it is true than from Git1.6.3, :

注意:它比来自Git1.6.3 的,是真的:

"git push" into a branch that is currently checked out will be refused by default.
You can choose what should happen upon such a push by setting the configuration variable receive.denyCurrentBranchin the receiving repository.

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

But I do not think this is what you are seeing right now.

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



As mentioned in "all about "bare" repos -- what, why, and how to fix a non-bare push" (at the bottom)

正如“关于“裸”存储库的所有内容——什么、为什么以及如何修复非裸推送中所述(在底部)

To make it a "real" bare repo, just delete all the files except .git, then mv .git/* .; rmdir .git.
Finally, edit the file called configand change bare = falseto bare = true.

要使其成为“真正的”裸存储库,只需删除除.git, then之外的所有文件mv .git/* .; rmdir .git
最后,编辑调用的文件config并更改bare = falsebare = true.

So if your destination repo has a configfile with bare = true, it is a bare repo.

所以如果你的目标仓库有一个config带有的文件bare = true,它就是一个裸仓库。

回答by Bombe

The message you're getting means that your remote repository is empty (which has nothing to do with being bare). When pushing into a remote repository for the first time you need to specify what to push:

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

git push origin master

This will push your current master branch to the remote repository. Subsequent invocations of git pushwill pushing “matching” branches, i.e. if there's a “master” branch in the remote repository your local “master” branch will be pushed to it.

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

回答by Newton fan 01

try

尝试

 $ git config --get core.bare

回答by Bill Heitstuman

Open the configfile in the .getdirectory and look for bare = true.

打开config目录中的.get文件并查找bare = true.