Git不允许提交或推送本地更改

时间:2016-02-18 19:34:35

标签: git

我遇到了本地git存储库的问题。我正在尝试对文件进行更改,它要么不会提交文件,要么我添加文件并提交,远程不会接受它。

我首先使用clone或pull创建本地repo。

$ mkdir {projectDir}
$ cd {projectDir}/
$ git init
Initialized empty Git repository in F:/{projectDir}/.git/
$ git remote add origin {account}@{ssh-host}:/var/repo/{projectName}
$ git pull origin master
From {ssh-host}:/var/repo/{projectName}
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master

然后我做了一个小改动

$ vi pub/index.php (small change to an existing file)

然后我尝试提交更改

$ git commit -m 'minor change'
On branch master
Changes not staged for commit:
        modified:   pub/index.php

no changes added to commit

当我浏览StackExchange时,我发现了一堆建议将文件添加到本地仓库,这很奇怪,因为文件已经存在。但无论如何我都这样做了,我得到了

$ git add pub/index.php 
$ git commit -m 'minor change'
[master 4efd2ac] minor change
 1 file changed, 2 insertions(+), 2 deletions(-)

确定。所以,我试着推动它,它表明了对我的仇恨。

$ git push origin master
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 {account}@{ssh-host}:/var/repo/{projectName}
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '{account}@{ssh-host}:/var/repo/{projectName}'

遵循那里的建议只是让我回到原点,我所做的一切似乎都无法使本地和远程回购正确同步。

1 个答案:

答案 0 :(得分:4)

您已将非裸存储库设置为远程存储库,(如错误所示)不接受推送到其当前已检出的分支。你需要做的是从一个裸仓库克隆;很有可能{account}@{ssh-host}:/var/repo/{projectName}本身指向 遥控器的裸仓!如果是这样,请使用那个(假设您有权访问该机器)。

此外,FWIW,您确实需要在更改后git add文件,或使用git commit -a。我知道它似乎很奇怪,因为该文件已经在repo中,但它是您正在添加的文件的当前版本

相关问题