我的本地机器上有一个git repo。我(最初)将其推送到远程(Web服务器),我检查远程(在远程),以便文件可以由apache提供,我在我的本地更改文件,commit -a
然后我尝试再次推它,我总是得到一个错误。对于Svn来说这非常简单,我如何用git做到这一点?
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 298 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/Dev
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 inconsist
ent
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 ssh://mike628@192.168.2.2/var/www/UML/.git
! [remote rejected] Dev -> Dev (branch is currently checked out)
error: failed to push some refs to ......'
答案 0 :(得分:0)
您不应该推送到非裸存储库。有一个第三个回购定期从你推到的那个回购。如果没有你从远程方面明确地做到这一点,Git将不会改变你的遥控器的工作目录。
您正在处理DVCS,推拉与拉动的概念是一个重要的概念。
有关详细信息,请参阅progit.org/book。
希望这有帮助。
答案 1 :(得分:0)
暂时在服务器上创建一个新的临时分支,以便您推送:
git checkout -b temp
这可以确保您没有检出当前正在推送的分支。现在你应该从当地推动。
在Git中存在裸露和工作回购的概念,并且你推动的“中央”回购 - 回购通常是裸露的。这是一种最佳实践,可以防止您遭受很多痛苦。您还可以将服务器上的当前仓库转换为裸仓:
git config --bool core.bare true
(然后删除除.git
之外的所有内容)
或者,按照@adymitruk的说法行事。在继续之前,请了解有关Git和DVCS的更多信息。