【git私服推送文件出现的问题】refusing to update checked out branch: refs/heads/master

"remote:error:refusing to update checked out branch:refs/heads/master"的解决办法

转载http://www.cnblogs.com/cosiray/archive/2012/06/01/2530967.html

在使用Git Push代码到数据仓库时,提示如下错误:

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

错误原型

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 git@192.168.1.X:/var/git.server/.../web

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

error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web'

解决办法:

这是由于git默认拒绝了push操作,需要进行设置,修改.git/config文件后面添加如下代码:

[receive]
denyCurrentBranch = ignore

无法查看push后的git中文件的原因与解决方法

在初始化远程仓库时最好使用

git --bare init

而不要使用:git init

git init 和git --bare init 的具体区别:http://blog.haohtml.com/archives/12265

=================================================

如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上,  也即在远程仓库的目录下对应的文件还是之前的内容。

解决方法:

必须得使用命令 git reset --hard 才能看到push后的内容.

研究了很久不得其解,然后找到一条命令凑合着能用了:

登录到远程的那个文件夹,使用

git config --bool core.bare true

就搞定了。

贴一段参考文章:

Create a bare GIT repository

A small rant: git is unable to create a normal bare repository by itself. Stupid git indeed.

To be precise, it is not possible to clone empty repositories. So an empty repository is a useless repository. Indeed, you normally create an empty repository and immediately fill it:

git init git add .

However, git add is not possible when you create a bare repository:

git --bare init git add .

gives an error "fatal: This operation must be run in a work tree".

You can't check it out either:

Initialized empty Git repository in /home/user/myrepos/.git/ fatal: http://repository.example.org/projects/myrepos.git/info/refs not found: did you run git update-server-info on the server? git --bare init git update-server-info # this creates the info/refs file chown -R <user>:<group> . # make sure others can update the repository

The solution is to create another repository elsewhere, add a file in that repository and, push it to the bare repository.

mkdir temp; cd temp git init touch .gitignore git add .gitignore git commit -m "Initial commit" git push <url or path of bare repository> master cd ..; rm -rf temp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个错误提示通常表示你正在尝试向 Git 服务器的主分支(master分支)推送更改,但是 Git 服务器上的钩子(hook)拒绝了推送操作。这可能是由于多种原因引起的,最常见的原因是你试图将不兼容的更改推送到远程主分支上。 解决此问题的最佳方法是首先确保你的本地分支是与远程主分支同步的。可以使用以下命令获取最新的远程变更: ``` git fetch origin ``` 然后,将本地分支与远程分支进行合并: ``` git merge origin/master ``` 如果本地分支有冲突,需要解决冲突并提交更改。然后再次尝试推送: ``` git push origin master ``` 如果问题仍然存在,可能需要检查 Git 服务器上的钩子以查找其他问题。 ### 回答2: 当使用`git http push`命令时,如果出现`refs/heads/master:refs/heads/master [remote rejected] (pre-receive hook declined)`的错误提示,通常是由于服务器端的`pre-receive hook`脚本拒绝了推送操作导致的。 在Git中,`pre-receive hook`是服务器端的一个钩子脚本,用于在接收到推送操作之前执行一些检查和验证。这个脚本可以被用来限制某些不允许的操作,例如禁止强制推送或者限制特定分支的修改权限。 导致出现错误的原因可能有以下几种: 1. 权限不足:服务器可能已经配置了`pre-receive hook`脚本,用于验证用户的权限或限制特定操作。如果你没有足够的权限执行推送操作,就会出现错误。 2. 推送的分支被锁定:服务器端可能配置了锁定某些分支的操作,防止不必要的修改。如果你试图推送被锁定的分支,就会出现错误。 3. 钩子脚本的逻辑检查不通过:`pre-receive hook`脚本可能包含了一些自定义逻辑检查,用于验证推送操作的合法性。如果你的推送操作不满足这些逻辑检查的条件,就会出现错误。 要解决该问题,你可以尝试以下几个步骤: 1. 检查你的权限:确认你有足够的权限进行推送操作,如果没有,请联系服务器管理员或拥有足够权限的人员。 2. 检查分支锁定:确认你试图推送的分支没有被锁定,如果有,在解锁之前无法进行推送操作。 3. 检查钩子脚本:检查服务器端的`pre-receive hook`脚本,了解其中包含的逻辑检查和验证规则。确保你的推送操作满足这些规则,否则需要进行相应的修改。 总之,该错误提示提示了推送操作被服务器端的`pre-receive hook`脚本拒绝。通过检查权限、分支锁定和钩子脚本等方面,可以解决这个问题。 ### 回答3: 当在git中使用HTTP协议进行push操作时,可能会出现以下错误提示:"refs/heads/master:refs/heads/master [remote rejected] (pre-receive hook declined)"。这个错误提示通常是由于pre-receive hook拒绝了push操作导致的。 Pre-receive hook是一个在git服务器上运行的脚本,用于在push操作之前执行一些自定义的验证或审查操作。这些操作可能包括检查提交的代码是否符合公司的代码规范、验证用户的权限等。 当出现上述错误时,说明你所执行的push操作被pre-receive hook拒绝了。这可能是由于以下一些原因导致的: 1. 代码规范不符:pre-receive hook可能会检查提交的代码是否符合特定的代码规范。如果你的提交代码不符合这些规范,就会导致push操作被拒绝。 2. 权限不足:pre-receive hook还可以用来验证用户的权限,以确保只有授权用户能够进行push操作。如果你的权限不足,就会导致push操作被拒绝。 解决这个问题的方法是根据具体的原因进行相应的调整和修复。如果是代码规范问题,你需要检查自己的代码是否符合要求,并进行相应的修改。如果是权限问题,你需要联系相应的管理员,获取足够的权限来执行push操作。 最后,如果你无法解决这个问题,你可以尝试使用其他协议(如SSH)来进行push操作,或者与git服务器的管理员联系,寻求进一步的帮助和指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值