从生产文件夹创建一个git存储库 [英] Creating a git repository from a production folder
问题描述
我有一台生产网站的机器,我想在该机器上创建一个git存储库,以便使用git来管理网站。
所以第一件事我做的是在生产机器上创建一个空的.git存储库: mkdir回购
cd回购
mkdir production.git
cd production.git
git init --bare
在这个仓库下hooks / post-receive我已经添加了以下几行:
#!/ bin / sh
GIT_WORK_TREE = / var / www / production_website git checkout -f
然后我下载了文件夹将我的制作网站放入我的本地机器并启动git:
cd production_website
git init
code>
之后,我做了第一次提交:
git add。
git commit -m第一次提交
最后,我添加了远程存储库并做了我的第一次推动:
git remote add origin ssh://myuser@productionmachine.com/repos/production.git
git push origin master
但是当我进行推送时,它给了我以下错误信息:
remote:fatal:该操作必须在工作树中运行
当接收到的挂钩被激活时,它会被触发。
做错了?
更新:
在第一步中,创建如果我使用 git init
而不是 git init --bare
我在生产机器中清空.git存储库错误消息: 远程:错误:拒绝更新签出分支:refs / heads / master
远程:e rror:默认情况下,更新非裸仓库中的当前分支
remote:error:被拒绝,因为它会使索引和工作树不一致
remote:错误:将需要'git reset --hard'来匹配
remote:error:工作树到HEAD。
remote:错误:
remote:错误:您可以在远程存储库中将'receive.denyCurrentBranch'配置变量设置为
remote:error:'ignore'或'warn',以允许推入
remote:错误:当前分支;然而,除非你
remote:error:安排它更新它的工作树来匹配你在
remote:error:other方面推送的内容,否则不建议这样做。
remote:error:
remote:error:为了压制此消息并保持默认行为,请将
remote:error:'receive.denyCurrentBranch'配置变量设置为'拒绝'。
我宁愿保持回购仓位,然后在post-receive hook
cd / path / to / non-bare / repo
git --git-dir / path / to / non-bare / repo / .git --work-tree = / path / to / non-bare / repo pull
即:
- 从裸仓库(您可以推入)拉出,然后从而不是试图直接推送到裸仓库(这很困难,如第二个非裸仓库) //www.ibm.com/developerworks/cn/websphere/library/default.asp?url=http://www.ibm.com/developerworks/cn/websphere/library/default.asp?url=http://blog.csdn.net/shenzhen/article/article/details/618520我怎样才能用git裸仓库推入非裸仓库? $ b
I have a machine with a production website, I want to create a git repository in that machine in order to manage the website using git.
So the first thing I did was to create an empty .git repository in the production machine:
mkdir repos cd repos mkdir production.git cd production.git git init --bare
In this repository under hooks/post-receive I've added the following lines:
#!/bin/sh GIT_WORK_TREE=/var/www/production_website git checkout -f
Then I've downloaded the folder with my production website into my local machine and started git:
cd production_website git init
After that I made the first commit:
git add . git commit -m "first commit"
And finally I've added the remote repository and made my first push:
git remote add origin ssh://myuser@productionmachine.com/repos/production.git git push origin master
But when I make the push it gives me the following error message:
remote: fatal: This operation must be run in a work tree
Which it's triggered when the post-receive hook it's activated.
Any suggestions of what I might be doing wrong?
UPDATE:
In the first step, when creating an empty .git repository in the production machine, if I use
git init
instead ofgit init --bare
I get this error message when making a push:remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository remote: error: is denied, because it will make the index and work tree inconsistent remote: error: with what you pushed, and will require 'git reset --hard' to match remote: error: the work tree to HEAD. remote: error: remote: error: You can set 'receive.denyCurrentBranch' configuration variable to remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into remote: error: its current branch; however, this is not recommended unless you remote: error: arranged to update its work tree to match what you pushed in some remote: error: other way. remote: error: remote: error: To squelch this message and still keep the default behaviour, set remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
解决方案I would rather keep the repo bare, then in the post-receive hook
cd /path/to/non-bare/repo git --git-dir /path/to/non-bare/repo/.git --work-tree=/path/to/non-bare/repo pull
That is:
- pulling from a bare repo (to which you can push), and then pulling from a second non-bare repo
- instead of trying to push directly to a bare repo (which is difficult, as explained in "How can I use a git bare repository to push into a non-bare repository?")
这篇关于从生产文件夹创建一个git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!