Git 错误:src refspec master 不匹配任何
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5802426/
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
Git error: src refspec master does not match any
提问by Mithun Sreedharan
I need to create a repo named carboncake
.
我需要创建一个名为carboncake
.
I tried this:
我试过这个:
Cloned the gitosis-admin repository to my local machine
将 gitosis-admin 存储库克隆到我的本地机器
$ git clone [email protected]:repositories/gitosis-admin.git
$ cd gitosis-admin
$ vim gitosis.conf
Added the [repo carboncake]
and [group carboncake]
section to the end of the file
将[repo carboncake]
和[group carboncake]
部分添加到文件末尾
[gitosis]
[group team]
writable = sweepshots
members = git_id_rsa
[group gitosis-admin]
writable = gitosis-admin
members = git_id_rsa
[repo carboncake]
description = A brand new app by Mithun.
owner = Mithun P
[group carboncake]
writable = myappname
members = mithun @core
Then copied the pub key file generated by Putty (I'm using Git basg for Windows):
然后复制Putty生成的pub密钥文件(我使用的是Git basg for Windows):
$cp /some/where/mithun.pub keydir/mithun.pub
$cp /some/where/mithun.pub keydir/mithun.pub
Executed the following commands:
执行了以下命令:
$ git add gitosis.conf keydir/mithun.pub
$ git commit -m "Added 'carboncake' repository and 'mithun' user."
$ git pull --rebase
$ git push
But it doesn't create any carboncake.git in My Server.
但它不会在我的服务器中创建任何 carboncake.git。
So I followed this:
所以我遵循了这个:
Executed the following commands on the server:
在服务器上执行以下命令:
$ su gitosis
$ git init --bare /srv/gitosis/repositories/carboncake.git
Here's my problem:
这是我的问题:
I tried to checkout/clone the new repository from my local machine
我试图从我的本地机器签出/克隆新的存储库
$ mkdir carboncake
$ cd carboncake
$ git init
$ touch a_text_file.txt
$ git add a_text_file.txt
$ git remote add origin [email protected]:repositories/carboncake.git
$ git push origin master
Which returned the error:
返回错误:
error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:repositories/carboncake.git'
When I tried git push origin HEAD:master
it returned the error:
当我尝试git push origin HEAD:master
它返回错误:
error: src refspec HEAD does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:repositories/carboncake.git'
When I tried git push origin master:refs/heads/master
it returned the error:
当我尝试git push origin master:refs/heads/master
它返回错误:
error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:repositories/carboncake.git'
git show-ref
on the local machine does not display anything
git show-ref
在本地机器上不显示任何内容
Also /srv/gitosis/repositories/carboncake.git/refs/heads/
directory on the server is empty.
同时/srv/gitosis/repositories/carboncake.git/refs/heads/
在服务器上的目录是空的。
How can I fix this?
我怎样才能解决这个问题?
回答by Mark Longair
You've created a new repository and added some files to the index, but you haven't created your first commit yet. After you've done:
您已经创建了一个新的存储库并向索引添加了一些文件,但是您还没有创建您的第一个提交。完成后:
git add a_text_file.txt
... do:
... 做:
git commit -m "Initial commit."
... and those errors should go away.
...这些错误应该消失。
回答by Mauvis Ledford
The quick possible answer: When you first successfully clone an empty git repository, the origin has no master branch. So the first time you have a commit to push you must do:
可能的快速答案:当您第一次成功克隆一个空的 git 存储库时,源没有主分支。因此,第一次提交推送时,您必须执行以下操作:
git push origin master
Which will create this new master branch for you. Little things like this are very confusing with git.
这将为您创建这个新的主分支。像这样的小事情与 git 非常混淆。
If this didn't fix your issue then it's probably a gitolite-related issue:
如果这不能解决您的问题,那么它可能是一个与 gitolite 相关的问题:
Your conf file looks strange. There should have been an example conf file that came with your gitolite. Mine looks like this:
你的 conf 文件看起来很奇怪。您的 gitolite 中应该有一个示例 conf 文件。我的看起来像这样:
repo phonegap
RW+ = myusername otherusername
repo gitolite-admin
RW+ = myusername
Please make sure you're setting your conf file correctly.
请确保您正确设置了 conf 文件。
Gitolite actually replaces the gitolite user's account with a modified shell that doesn't accept interactive terminal sessions. You can see if gitolite is working by trying to ssh into your box using the gitolite user account. If it knows who you are it will say something like "Hi XYZ, you have access to the following repositories: X, Y, Z" and then close the connection. If it doesn't know you, it will just close the connection.
Gitolite 实际上用不接受交互式终端会话的修改过的 shell 替换了 gitolite 用户的帐户。您可以通过尝试使用 gitolite 用户帐户 ssh 进入您的盒子来查看 gitolite 是否正常工作。如果它知道您是谁,它会说“嗨 XYZ,您可以访问以下存储库:X、Y、Z”,然后关闭连接。如果它不认识你,它只会关闭连接。
Lastly, after your first git push failed on your local machine you should never resort to creating the repo manually on the server. We need to know why your git push failed initially. You can cause yourself and gitolite more confusion when you don't use gitolite exclusively once you've set it up.
最后,在你的本地机器上你的第一次 git push 失败后,你不应该诉诸于在服务器上手动创建 repo。我们需要知道为什么您的 git push 最初失败。如果您在设置后不专门使用 gitolite,您可能会导致您自己和 gitolite 更加混乱。