<p>在使用Git Push代码到数据仓库时,提示如下错误:</p><pre class="brush:bash;toolbar:false">[remoterejected]master-&gt;master(branchiscurrentlycheckedout)</pre><p>错误原型</p><pre class="brush:bash;toolbar:false">remote:error:refusingtoupdatecheckedoutbranch:refs/heads/master remote:error:Bydefault,updatingthecurrentbranchinanon-barerepository remote:error:isdenied,becauseitwillmaketheindexandworktreeinconsistent remote:error:withwhatyoupushed,andwillrequire&#39;gitreset--hard&#39;tomatch remote:error:theworktreetoHEAD. remote:error: remote:error:Youcanset&#39;receive.denyCurrentBranch&#39;configurationvariableto remote:error:&#39;ignore&#39;or&#39;warn&#39;intheremoterepositorytoallowpushinginto remote:error:itscurrentbranch;however,thisisnotrecommendedunlessyou remote:error:arrangedtoupdateitsworktreetomatchwhatyoupushedinsome remote:error:otherway. remote:error: remote:error:Tosquelchthismessageandstillkeepthedefaultbehaviour,set remote:error:&#39;receive.denyCurrentBranch&#39;configurationvariableto&#39;refuse&#39;. Togit@192.168.1.X:/var/git.server/.../web ![remoterejected]master-&gt;master(branchiscurrentlycheckedout) error:failedtopushsomerefsto&#39;git@192.168.1.X:/var/git.server/.../web&#39;</pre><p>解决办法:</p><p>这是由于git默认拒绝了push操作,需要进行设置,修改.git/config文件后面添加如下代码:</p><p>[receive]</p><p>denyCurrentBranch = ignore</p><p>无法查看push后的git中文件的原因与解决方法</p><p>在初始化远程仓库时最好使用</p><p>git --bare init</p><p>而不要使用:git init</p><p>git init 和git --bare init 的具体区别:http://blog.haohtml.com/archives/12265</p><p>=================================================</p><p>如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上, 也即在远程仓库的目录下对应的文件还是之前的内容。</p><p>解决方法:</p><p>必须得使用命令 git reset --hard 才能看到push后的内容.</p><p>研究了很久不得其解,然后找到一条命令凑合着能用了:</p><p>登录到远程的那个文件夹,使用</p><pre class="brush:bash;toolbar:false">gitconfig--boolcore.baretrue</pre><p>就搞定了。</p><p>贴一段参考文章:</p><pre class="brush:bash;toolbar:false">CreateabareGITrepository Asmallrant:gitisunabletocreateanormalbarerepositorybyitself.Stupidgitindeed. Tobeprecise,itisnotpossibletocloneemptyrepositories.Soanemptyrepositoryisauselessrepository.Indeed,younormallycreateanemptyrepositoryandimmediatelyfillit: gitinitgitadd. However,gitaddisnotpossiblewhenyoucreateabarerepository: git--bareinitgitadd. givesanerror&quot;fatal:Thisoperationmustberuninaworktree&quot;. Youcan&#39;tcheckitouteither: InitializedemptyGitrepositoryin/home/user/myrepos/.git/fatal:http://repository.example.org/projects/myrepos.git/info/refsnotfound:didyourungitupdate-server-infoontheserver?git--bareinitgitupdate-server-info#thiscreatestheinfo/refsfilechown-R&lt;user&gt;:&lt;group&gt;.#makesureotherscanupdatetherepository Thesolutionistocreateanotherrepositoryelsewhere,addafileinthatrepositoryand,pushittothebarerepository. mkdirtemp;cdtempgitinittouch.gitignoregitadd.gitignoregitcommit-m&quot;Initialcommit&quot;gitpush&lt;urlorpathofbarerepository&gt;mastercd..;rm-rftemp</pre>
T:0.006516s,M:247.99 KB
返回顶部 留言