推送到 git 存储库不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3191400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:23:45  来源:igfitidea点击:

pushing to a git repository does not work

gitversion-controlversioning

提问by Coder

I am just starting out with GIT (i'm coming from cvs) and would like to set up something akin to cvs/svn with Git. I performed the following steps:

我刚开始使用 GIT(我来自 cvs)并且想用 Git 设置类似于 cvs/svn 的东西。我执行了以下步骤:

cd o:/repository
git init

cd <working directory>
git clone o:/repository

i now created a file called file.txt with some content doing a "git status" lists appropriate changes.

我现在创建了一个名为 file.txt 的文件,其中的一些内容执行“git status”列出适当的更改。

I then do

然后我做

git add file.txt
git commit file.txt

and both seem to work fine.

并且两者似乎都可以正常工作。

When i do git push, i get the following error:

当我这样做时 git push,我收到以下错误:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'o:/repository'

I tried doing a pull first, as well as specifying origin and master variations to the push command but none work.

我尝试先进行拉取,并指定推送命令的原点和主变体,但没有任何效果。

Can someone please tell me what i am missing. I am running Windows 7 64 bit.

有人可以告诉我我错过了什么。我正在运行 Windows 7 64 位。

Ps. I also tried

附言。我也试过

git push origin master

and i get the following:

我得到以下信息:

Counting objects: 3, done.
Writing objects: 100% (3/3), 251 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), 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 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 O:/repository
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'O:/repository'

回答by Geoff Lanotte

This happened to us a few weeks ago. It means that you have a working directory checked out in your origin repository and you cannot push to overwrite.

这发生在我们几个星期前。这意味着您在源存储库中检出了一个工作目录,并且无法推送覆盖。

at the origin you need to bare the repository. I don't know of a way to do it with one command. What I did (at the origin repository)

在原点,您需要裸露存储库。我不知道用一个命令来完成它的方法。我做了什么(在原始存储库中)

> mv repository repository.old
> git clone --bare repository.old repository

I see that the origin in your case is the o:/repository. The origin, should not be a checked out working copy, so you can init a bare repository or copy as per above. To get the scenario you described to pass:

我看到您的案例的来源是 o:/repository。原点不应是已检出的工作副本,因此您可以按照上述方法初始化裸存储库或副本。要使您描述的场景通过:

cd o:/repository
git init  --bare

cd <working directory>
git clone o:/repository

git push origin master

this should work just fine for you:

这应该适合你:

good reading: http://www.gitready.com/advanced/2009/02/01/push-to-only-bare-repositories.html

好读物:http: //www.gitready.com/advanced/2009/02/01/push-to-only-bare-repositories.html

回答by Eli Barzilay

For the first push you'll need something like

对于第一次推送,您需要类似的东西

git push origin master

See also the push.defaultoptionoption.

另请参阅push.default选项选项。

In any case, if you're later going to run into a problem of pushing to a non-bare repository, so you'll need to read about that too.

无论如何,如果您稍后会遇到推送到非裸存储库的问题,那么您也需要阅读相关内容。

回答by VonC

If you still want to push to a checked out branch of a remote non-bare repo, it is now possible (Git 2.3.0, February 2015), provided there is no modified files in the target working tree.

如果您仍想推送到远程非裸存储库的签出分支,现在可以(Git 2.3.0,2015 年 2 月),前提是目标工作树中没有修改过的文件。

In that remote repo, do:

在该远程仓库中,执行以下操作:

git config receive.denyCurrentBranch=updateInstead

It is more secure than config receive.denyCurrentBranch=ignore: it will allow the push only if you are not overriding modification in progress.

它比 config 更安全receive.denyCurrentBranch=ignore:只有当您没有覆盖正在进行的修改时,它才会允许推送。

See commit 1404bcbby Johannes Schindelin (dscho):

提交1404bcb约翰内斯Schindelin( )dscho

receive-pack: add another option for receive.denyCurrentBranch

When synchronizing between working directories, it can be handy to update the current branch via 'push' rather than 'pull', e.g. when pushing a fix from inside a VM, or when pushing a fix made on a user's machine (where the developer is not at liberty to install an ssh daemon let alone know the user's password).

The common workaround – pushing into a temporary branch and then merging on the other machine – is no longer necessary with this patch.

The new option is:

receive-pack: 添加另一个选项 receive.denyCurrentBranch

在工作目录之间同步时,通过 ' push' 而不是 ' pull'更新当前分支会很方便,例如当从 VM 内部推送修复时,或者当推送在用户机器上进行的修复时(开发人员不在安装 ssh 守护进程的自由,更不用说知道用户的密码了)。

这个补丁不再需要常见的解决方法——推送到一个临时分支,然后在另一台机器上合并。

新选项是:

updateInstead

Update the working tree accordingly, but refuse to do so if there are any uncommitted changes.

相应地更新工作树,但如果有任何未提交的更改,则拒绝这样做。

回答by Amber

As the error message states, the branch you're trying to push to (master) is checked out in the originrepository. You could solve this by going to o:/repositoryand checking out a different branch.

正如错误消息所述,您尝试推送到 ( master)的分支已在origin存储库中签出。您可以通过转到o:/repository并检查不同的分支来解决此问题。