use*_*481 42 git git-push git-config git-non-bare-repository
我有一个Git存储库.我克隆了存储库,可以提交我的本地更改.当我将更改推送到服务器时,它可以工作.
一旦我创建了一个分支,我就会检查分支,提交我的工作,然后检查主分支.然后我将我的本地更改合并到主分支中.当我尝试推送到服务器时,我得到以下异常:
Welcome to Git (version 1.7.11-preview20120620)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
$ git push origin master:master
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 13.68 KiB, done.
Total 8 (delta 2), reused 1 (delta 0)
Unpacking objects: 100% (8/8), done.
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'.
To c:/jGit
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'c:/gitRepository'
Run Code Online (Sandbox Code Playgroud)
一种解决方案是运行以下命令:
git config receive.denyCurrentBranch ignore
Run Code Online (Sandbox Code Playgroud)
在此之后它可以工作,但我想知道为什么我需要使用此选项.这是唯一的选择吗?这样做有什么后果?
我真正想做的是创建分支,将它们合并到主分支中,然后将我的更改推送到服务器.
kan*_*kan 27
您要推送的服务器应该使用裸存储库.
小智 24
原来的海报说:
一种解决方案是运行以下命令:
Run Code Online (Sandbox Code Playgroud)git config receive.denyCurrentBranch ignore
在此之后它可以工作,但我想知道为什么我需要使用此选项.这是唯一的选择吗?这样做有什么后果?
正如我在回答类似问题时所指出的,自Git 1.6.2版以来,Git默认不会让你推送到非裸存储库.这是因为该git push
命令仅更新HEAD
远程存储库上的分支和引用.什么是不这样做也更新非裸远程工作拷贝和舞台区.
因此,当您git status
在远程仓库中使用时,您将看到repo的先前状态仍然存在于工作副本中(并且在索引中暂存):
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: previous-state.txt
Run Code Online (Sandbox Code Playgroud)
如果您查看第一次尝试将receive.denyCurrentBranch
设置设置为默认refuse
值时推送到非裸机远程仓库时收到的错误消息,您将看到该消息告诉您基本相同的事情:
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error:
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
Run Code Online (Sandbox Code Playgroud)
正如指出的一些在其他的答案,你真不该推到非纯仓库,因为我上面所指出的原因,和Git的本身告诉你的.
就像这个答案所说的那样,将现有的非裸仓库转换成裸仓库的简单方法就是将其作为一个简单的仓库简单地重新放置:
git clone --bare old-repo
Run Code Online (Sandbox Code Playgroud)
或者你可以尝试搞乱core.bare
配置设置,详见答案.
我遇到了同样的错误,并且需要将存储库作为一个开发测试页面在线运行(也就是说,我想,保持一个非裸的回购).希望我通过使用这一系列命令启动存储库来解决它(从git 2.3开始):
git init
git config --global user.email "your@mail.here"
git config --global user.name "Your Name"
git commit
git config receive.denyCurrentBranch updateInstead
Run Code Online (Sandbox Code Playgroud)
如下所示: 无法推入git存储库
归档时间: |
|
查看次数: |
56586 次 |
最近记录: |