2015-09-06 98 views
0

我一直在四处搜寻以找出如何解决此问题,但似乎无法找到适合我的任何内容。所以我想我会问你。即使远程设置为裸设备,无法推送到远程存储库

我最近学会了如何使用git进行源代码控制,并决定我想开始将它用于我已经构建的网站。我有网站的服务器(不是我自己的,从arvixe购买服务器空间)已经安装了git。我开始(通过SSH)将我的主文件夹和运行

git init 

设置,然后我想添加的所有我已经有文件夹中的文件与git所以我跑:

git add . 

然后提交它们:

git commit . 

我希望能够从我的笔记本电脑推到服务器,所以我这样做是为了得到一个纯仓库:

git init --bare 

(我在google搜索了这个问题后发现它在其他情况下有效。在此之前,我尝试通过ssh检查一个虚拟分支,但是当我做到这一点时,从笔记本电脑到服务器的任何事情都没有改变。)

之后,我通过ssh和sourcetree将存储库克隆到我的笔记本电脑上。当我把我的笔记本电脑的变化和尝试将它们推送到远程的回购我收到此错误信息:

stdin: is not a tty 

/etc/bashrc: line 100: $HISTFILE: ambiguous redirect 

remote: error: refusing to update checked out branch: refs/heads/master[K 
remote: error: By default, updating the current branch in a non-bare repository[K 
remote: error: is denied, because it will make the index and work tree inconsistent[K 
remote: error: with what you pushed, and will require 'git reset --hard' to match[K 

remote: error: the work tree to HEAD.[K 
remote: error: [K 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K 
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K 
remote: error: its current branch; however, this is not recommended unless you[K 
remote: error: arranged to update its work tree to match what you pushed in some[K 
remote: error: other way.[K 
remote: error: [K 
remote: error: To squelch this message and still keep the default behaviour, set[K 
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K 
To ssh://[email protected]/home/ihlenfmt 

! [remote rejected] master -> master (branch is currently checked out) 

我很新与git所以它极有可能我做了一些愚蠢的事。任何人都能看到我出错的地方吗?

+1

“这个我试过检查出通过ssh的虚拟分支,但是当我这样做什么,我从我的笔记本电脑推到了服务器实际上改变任何东西。之前”这是否意味着你在现有的仓库中运行'git init --bare'?现有的存储库将不能进行裸这种方式。相反,请在新目录中运行该命令。 – Chris

+0

同意@克里斯,或者您可以通过删除所有文件和目录(除'.git'),移动.git'的'所有内容到项目的根把非裸露回购成裸露的回购协议,删除' .git'并设置'core.bare'为'真'的配置(详见这个答案http://stackoverflow.com/a/2200662/1157272通过@约尔格-W-午报) – joran

回答

0

问题:您想将内容推送到非裸露的服务器回购站(将文件签出为工作副本)。从技术上讲,这是可能的,但这不是一个“正常”的设置。我会给你一个“修复”您目前的情况第一: 或者:

一)您的服务器上,初始化混帐回购协议为“裸”,即

git config core.bare true 

这样,您就可以访问此从其他机器使用其中一个允许的git协议(包括ssh)。

或b)在服务器计算机上:

git config receive.denyCurrentBranch ignore 

OR(GIT V2.3 +)C)

git config --local receive.denyCurrentBranch updateInstead 

请记住,以上选项会造成问题的道路当你从你的笔记本电脑推送并同时在服务器上提交时。

更好的解决方案是在其他地方(甚至在同一台服务器上)创建一个单独的git仓库,可以通过您的Web服务器帐户和笔记本电脑访问它。然后在你的网络服务器和笔记本电脑中克隆这个回购。例如:

</home/user/some-dir-accessible-via-ssh>$ git init . --bare 
</your-webserver-root>$ git init . #(not bare) 
</your-webserver-root>$ git commit #(etc) 
</your-webserver-root>$ git push </home/user/some-dir-accessible-via-ssh> master 

如果所有作品,

</your-webserver-root>$ git remote add origin </home/user/some-dir-accessible-via-ssh> 

笔记本电脑

$git clone <ssh://[email protected]/home/user/some-dir-accessible-via-ssh> 

您的工作流程是这样的:在你的笔记本电脑

  • 工作,拉,然后推送到服务器。
  • 转到服务器,从产地拉
  • 使服务器上进行更改。推到原点
+0

我给这一试!谢谢! – mtihlenfield

+0

这工作得很好!谢谢! – mtihlenfield

相关问题