git“更新当前签出的分支”警告是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/738154/
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 03:38:43  来源:igfitidea点击:

What does git "updating currently checked out branch" warning mean?

git

提问by skiphoppy

When I do a git push, I see the following:

当我执行 git push 时,我看到以下内容:

warning: updating the currently checked out branch; this may cause confusion,
as the index and working tree do not reflect changes that are now in HEAD.

I Googled for this message, and all I can find is a git mailing list discussionwhere the authors try to decide exactly how to make this message better to communicate to me what the real problem is.

我在谷歌上搜索了这条消息,我能找到的只是一个git 邮件列表讨论,作者试图确切地决定如何使这条消息更好地传达给我真正的问题是什么。

How did I cause this, and how do I fix it?

我是如何导致这种情况的,我该如何解决?

回答by Brian Campbell

This happens when you are pushing to a non-bare repo. A bare repo is one that consists solely of a .gitdirectory; a non-bare repo also includes a checkout. In general, you should not push to a non-bare repo; in fact, in future version of git, that will be forbidden. If you push to a non-bare repo, then the HEAD of that repo will be out of sync with the index and the working copy.

当您推送到非裸存储库时会发生这种情况。裸仓库是仅由.git目录组成的仓库;非裸回购还包括结帐。一般来说,你不应该推送到非裸仓库;事实上,在未来的 git 版本中,这将被禁止。如果你推送到一个非裸仓库,那么该仓库的 HEAD 将与索引和工作副本不同步。

If you're creating a repo that people are going to want to push to, then you should create it using git init --bare(and git init --bare --sharedif several user accounts need access to it), or git clone --bareif you're creating it by cloning an existing repo.

如果您正在创建一个人们想要推送到的存储库,那么您应该使用git init --bare(并且git init --bare --shared如果多个用户帐户需要访问它)git clone --bare来创建它,或者如果您通过克隆现有存储库来创建它。

回答by VonC

In short, your remote repository is no longer a bare one, and you pushing on the remote checkout branch.

简而言之,您的远程存储库不再是一个裸存储库,而您正在推动远程结帐分支。

See "How to publish a Git repository":

请参阅“如何发布 Git 存储库”:

A bare repository is one without a checked out working copy of the code. It only contains the git database.
As a general rule you should never push into a repository that contains changes in the working copy.
To ensure this doesn't happen, we're making the server repository a bare repository - it has no working copy

裸存储库是没有代码的检出工作副本的存储库。它只包含 git 数据库。
作为一般规则,您永远不应该推送到包含工作副本更改的存储库。
为确保不会发生这种情况,我们将服务器存储库设为裸存储库 - 它没有工作副本

From here:

这里

Note that the target of a "push" is normally a barerepository (i.e., with no work tree of its own).
You can also push to a repository that has a checked-out working tree, but the working tree will not be updated by the push.
This may lead to unexpected results if the branch you push to is the currently checked-out branch.

请注意,“推送”的目标通常是一个仓库(即,没有自己的工作树)。
您还可以推送到具有签出工作树的存储库,但推送不会更新工作树。
如果您推送到的分支是当前检出的分支,这可能会导致意外结果。

If a detached work tree is defined (which can for instance correspond to a web server's DocumentRoot), you need to :

如果定义了分离的工作树(例如可以对应于 Web 服务器的 DocumentRoot),您需要:

Check, on your remote repository, the value of git config core.worktreeand git config core.bare

在您的远程存储库中检查git config core.worktree和的值git config core.bare

回答by VonC

I made my repository bare by cloning a new, bare, repository from my messed up one, saving the messed-up one just in case, and replacing it with my cloned bare one.

我通过从我搞砸的存储库中克隆一个新的裸存储库来使我的存储库变得裸露,保存混乱的存储库以防万一,并用我克隆的裸存储库替换它。

I'm new to git, and when I set up the repsitory, I forgot to use the --bare option. Thanks for all your help!

我是 git 新手,当我设置存储库时,我忘记使用 --bare 选项。感谢你的帮助!

I've since read the O'Reilly git book and now am a total git convert.

从那以后,我阅读了 O'Reilly git 书,现在完全是 git 转换者。