简体   繁体   English

git错误-“错误:src refspec master不匹配。”

[英]git error - “error: src refspec master does not match any.”

I'm trying to setup a push to deploy process over my home network. 我正在尝试设置一个推送,以在我的家庭网络上部署流程。 I'm trying to have a setup where I can run a process (I'll put into a bash script in time) on the server that will setup the empty repository there. 我正在尝试进行设置,以便可以在服务器上运行一个进程(将及时放入bash脚本中),该进程将在此处设置空存储库。 Then, from my development device, I'll push to that repo on the server. 然后,从开发设备中,我将推送到服务器上的该存储库。

I'm working from a slightly modified version of the following tutorial. 我正在使用以下教程的稍作修改的版本。 The tutorial seems to assume that the project is currently sitting on the server. 该教程似乎假定该项目当前位于服务器上。 I want to create the project in my development environment then have the server setup where I can then push the project to the server. 我想在开发环境中创建项目,然后进行服务器设置,然后将项目推送到服务器。

http://danbarber.me/using-git-for-deployment/ http://danbarber.me/using-git-for-deployment/

1) Here is my process I follow to setup the live repo and the bare repo on the server: 1)这是我在服务器上设置实时仓库和裸仓库的过程:

# create our app space and initialise git
mkdir /var/www/myproject && cd /var/www/myproject
git init
touch README.md
git add .
git commit -m "Setup new project"

# create bare repository
mkdir -p /var/git/myproject.git
cd /var/git/myproject.git
git init --bare
cd /var/www/myproject
git push /var/git/myproject.git master # error here too "error: src refspec master does not match any."

# configure /var/www/myproject/.git/config
cd /var/www/myproject/
git remote add hub /var/git/myproject.git

# create hook to make sure that any time anything is pushed to the hub repository it will be pulled into the live repo
# write this to /var/git/myproject.git/hooks/post-update

#!/bin/sh

echo
echo "**** Pulling changes into Live [Hub's post-update hook]"
echo

cd /var/www/myproject || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info
^D

# make sure the file is executable
chmod +x /var/git/myproject.git/hooks/post-update

# create hook to make sure that any ‘in place’ changes we make to the web code is pushed to the hub when committed
# **write this to /var/www/myproject/.git/hooks/post-commit

#!/bin/sh

echo
echo "**** pushing changes to Hub [Live's post-commit hook]"
echo

git push hub
^D

# Again, ensure this file is executable.
chmod +x /var/www/myproject/.git/hooks/post-commit

2) The on my development device I do the following: 2)在开发设备上,我执行以下操作:

rails new myproject
cd myproject
git init
git remote add origin martyn@192.168.0.100:/var/git/myproject.git
git push origin master

..but I get the following error: ..但出现以下错误:

error: src refspec master does not match any.
error: failed to push some refs to 'martyn@192.168.0.100:/var/git/myproject.git'

..does anyone know what I need to do. ..有人知道我需要做什么。 Following the tutorial it assumes that the app already exists on the server, so it's slightly different in that it doesn't create an empty repo. 在学习本教程之后,它假定该应用程序已经存在于服务器上,因此它略有不同,因为它不会创建空的存储库。 But I don't want to FTP the apps files over, clone it from there then create a repo on the server. 但是我不想通过FTP将应用程序文件复制过来,从那里克隆它,然后在服务器上创建一个仓库。 I want to create the app in development environment, run a script on the server to setup git there, then push the app from dev to my server. 我想在开发环境中创建应用程序,在服务器上运行脚本以在其中设置git,然后将应用程序从dev推送到我的服务器。

Anyway this is my first time to try this, I'd appreciate any pointers or if anyone has a better suggestion to what I should be doing. 无论如何,这是我第一次尝试这种方法,对于任何指示,或者有人对我应该做的事情有更好的建议,我将不胜感激。 Thanks 谢谢

UPDATE: 更新:

I added touch README.md so that there is something to commit. 我添加了touch README.md以便可以提交一些内容。 Also, I added the code to setup an empty rails project and create the local repo. 另外,我添加了代码以设置一个空的Rails项目并创建本地存储库。 I get no errors on the server. 我在服务器上没有任何错误。 But I still can't do what I want to do on my development device. 但是我仍然无法在开发设备上做我想做的事情。 When I do the following though: 当我执行以下操作时:

cd /var/www/myproject
git clone martyn@192.168.0.100:/var/git/myproject.git myproject

I can clone down the repo from the server, then add files etc .. then push. 我可以从服务器克隆回购,然后添加文件等..然后推送。 But it's not how I want to create a new project. 但这不是我想要创建一个新项目的方式。 I want to first start building the app locally, create a local repo, .. then shortly after when I'm ready to commit, setup the server and PUSH files. 我想先开始在本地构建应用程序,创建本地存储库,然后在准备提交后不久设置服务器和PUSH文件。 Similar process to Heroku or Github, with those you don't have to clone an empty repo first from there before you can push. 与Heroku或Github相似的过程,您不必先从那里克隆空的仓库,然后再进行推送。 You can just push the files to there once their server is setup. 设置好服务器后,就可以将文件推送到那里。 This is similar to what I'm trying to do. 这类似于我正在尝试执行的操作。

There is no commit created on your local master branch. 在本地master分支上没有创建任何提交。 This will not make a commit if you don't have any files in directory: 如果目录中没有任何文件,则不会提交:

# create our app space and initialise git
mkdir /var/www/myproject && cd /var/www/myproject
git init
git add .
git commit -m "Setup new project"
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

Note "nothing to commit" line. 注意“没什么可提交的”行。 git log or git show will not show you any commits. git log或git show不会显示任何提交。 Make sure to create some files in repository directory before doing first git add. 确保在执行第一次git add之前在存储库目录中创建一些文件。

EDIT: 编辑:

Actually, technically there is no master branch in a brand new repository. 实际上,从技术上讲,全新存储库中没有主分支。 This just what HEAD points to: HEAD所指向的就是:

cat .git/HEAD
ref: refs/heads/master

git show-ref does not show any refs. git show-ref不显示任何参考。 Only after the first commit master branch is created and git show-ref shows: 仅在创建第一个提交主分支后,git show-ref才会显示:

git show-ref
bf07c8469f5e66eff66a0a3e9c652dcc347c1de8 refs/heads/master

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 git将新文件推送到裸仓库失败:“错误:src refspec master不匹配。”为什么? - git push new file to a bare repo failed: “error: src refspec master does not match any.” Why? 推送至“ fork” Git错误-src refspec master不匹配。 未能将一些引用推送到'https:// - Push to “fork” Git Error - src refspec master does not match any. failed to push some refs to 'https:// git push错误“错误:src refspec xxx不匹配。”使用git flow - git push error “error: src refspec xxx does not match any.” using git flow 错误:src refspec master 不匹配。 尝试推送到 Bitbucket 存储库时 - Error: src refspec master does not match any. when trying to push to Bitbucket repo 错误:src refspec master与any不匹配。未能将一些参考文献推送到heroku - error: src refspec master does not match any. failed to push some refs to heroku git->错误:src refspec master与任何不匹配 - Git --> error: src refspec master does not match any 错误:src refspec master 不匹配任何 - error: src refspec master does not match any 想了解错误原因:src refspec master does not match any。 错误:无法将一些引用推送到“https://github.com/xyz.git” - Want to understand the reason for error: src refspec master does not match any. error: failed to push some refs to 'https://github.com/xyz.git'' 当我执行“git push origin master”时,Github 出错(错误:src refspec master 不匹配) - Error in Github when I do “git push origin master” (error: src refspec master does not match any) git push到第二个git repo失败:错误:src refspec master与任何不匹配 - git push to second git repo fail: error: src refspec master does not match any
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM