git推送失败:“拒绝更新已签出的分支:refs/heads/master”



我想用git存储我对JBoss-config的本地修改。为此,我建立了以下结构:

lrwxrwxrwx  1 jboss jboss        19 Jan 24 11:53 current -> jboss-as-7.1.0.CR1b
drwxr-xr-x 11 jboss jboss      4096 Jan 24 12:13 jboss-as-7.1.0.CR1b
-rw-r--r--  1 jboss jboss 108211143 Jan 23 16:02 jboss-as-7.1.0.CR1b.tar.gz
drwxr-xr-x  6 jboss jboss      4096 Jan 24 11:36 local

local是git存储库,应为"原点"。这个想法是,一旦有更新可用,我希望能够轻松地更新我的JBoss发行版。我想将对分布式JBoss包的所有本地修改存储在git中。

所以,目前我这样做:

jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git init
Initialized empty Git repository in /opt/jboss/jboss-as-7.1.0.CR1b/.git/
jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git remote add origin ../local/   
jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git pull origin master 
From ../local
 * branch            master     -> FETCH_HEAD

到目前为止,我所有的本地修改都在我想要的地方。

然而,一旦我进行了本地修改,并想将它们重新插入local存储库,我就会得到一个错误:

jboss@tpl0:~/jboss-as-7.1.0.CR1b$ vim standalone/configuration/standalone.xml   
jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git commit -a -m "renamed database to project2_core,   to distinguish from other projects"
[master 3e54f34] renamed database to project2_core, to distinguish from other projects
Committer: jboss <jboss@tpl0.(none)>
 1 files changed, 1 insertions(+), 1 deletions(-)
jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git push origin master 
Counting objects: 9, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 447 bytes, done.
Total 5 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (5/5), 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 t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ../local/
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '../local/'

我该怎么办?非常感谢您的帮助!

编辑

以下是我所做的,它解决了问题:

cd ~/current
git init
vim .gitignore                   # set up a basic .gitignore file
git add .gitignore
git commit -a -m "initial commit"
cd ~/local
git clone ~/current
git branch -m master current     # rename master branch to 'current'
git branch repo
git checkout repo

现在,目录~/local中的分支current总是最新的,但它没有被检出,所以我可以推到它中。

推送适用于裸回购。对于非裸回购,你应该把它们拉进去。

如果您无论如何都想强制执行此操作,可以按照错误消息状态执行,并将receive.denyCurrentBranch设置为忽略。SSH到您要推送的回购的位置并运行:

git config receive.denyCurrentBranch ignore

远程站点的主分支已签出。如果您有权访问远程存储库,请签出任何其他分支,然后从存储库推送。

将原始(本地)存储库创建为裸存储库(即git init--bare),或者签出其中不是master的分支。

OR,

当您初始化远程项目时,使用

git init --bare

我通过从"current"中的"local"中提取而不是从"local’中推到"current’"来绕过这一问题。

我知道这是一个很老的问题,但如果使用git init--bare,请注意'git_DIR='如果在推送后使用挂钩来签出回购,则将为裸回购挂钩设置。在挂钩例程中使用"export GIT_DIR=.GIT",使其识别出您正在进入的回购。。。。

我的孤立情况

我不是先推到原点,而是把分支拉到同一网络上的其他机器上。

  • 计算机A)回购来源
  • 计算机B)从计算机A克隆的repo

错误

% git push local feat/async-updates
Enumerating objects: 25, done.
Counting objects: 100% (25/25), done.
Delta compression using up to 8 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 1.34 KiB | 1.34 MiB/s, done.
Total 13 (delta 12), reused 0 (delta 0), pack-reused 0
remote: Checking connectivity: 13, done.
remote: error: refusing to update checked out branch: refs/heads/feat/async-updates
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote: 
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote: 
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

最终,问题源于在计算机A(原始回购来源)上检查了同一分支机构。我切换到";dev";还有中提琴,问题解决了。

相关内容

最新更新