简体   繁体   English

Git是不允许的局部变化被提交或推

[英]Git is not allowing local changes to be committed or pushed

I am having an issue with a local git repository. 我在本地git存储库中遇到问题。 I am trying to make a change to a file and it either won't commit the file or if I add the file and the commit it the remote won't accept it. 我正在尝试对文件进行更改,它要么不会提交文件,要么如果我添加文件并提交它,则遥控器将不接受它。

I start by creating the local repo using clone or pull. 我首先使用clone或pull创建本地仓库。

$ 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

Then I make a minor change 然后我做了一个小小的改变

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

Then I attempt to commit the change 然后我尝试提交更改

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

no changes added to commit

When I look around StackExchange I find a bunch of suggestions to add the file to the local repo, which is weird because the file exists already. 当我环顾StackExchange时,会发现一堆将文件添加到本地存储库的建议,这很奇怪,因为文件已经存在。 But I do it anyway and I get 但是无论如何我都会得到

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

ok. 好。 So then I try to push it and it demonstrates its hatred for me. 因此,我尝试推动它,并向我展示了它的仇恨。

$ 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}'

Following the advice in there just puts me back to square one and nothing I do seems to be able to get the local and remote repos to sync up properly. 按照那里的建议,我只能回到第一个问题,而我似乎无能为力地使本地和远程存储库正确同步。

You have set up a non-bare repository as your remote, which (as the error says) does not accept pushes to its currently checked out branch. 您已将非裸存储库设置为您的远程存储库,该存储库(如错误所示)不接受对当前检出分支的推送。 What you need to do is instead clone from a bare repo; 您需要做的是从裸仓库中克隆; chances are very good that {account}@{ssh-host}:/var/repo/{projectName} itself points to a bare repo for its remote; {account}@{ssh-host}:/var/repo/{projectName}本身很可能指向远程的裸回购; if so, use that one (assuming you have access to that machine). 如果是这样,请使用该计算机(假设您可以访问该计算机)。

Also, FWIW, you indeed need to either git add a file after you change it, or use git commit -a . 同样,FWIW,您确实需要在更改文件后git add文件,或使用git commit -a I know it seems strange since the file is already in the repo, but it is your current version of the file that you are adding. 我知道这似乎很奇怪,因为该文件已经在存储库中,但这是您要添加的文件的当前版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM