将更改推送到远程存储库时,此Git警告消息是什么? [英] What is this Git warning message when pushing changes to a remote repository?

查看:85
本文介绍了将更改推送到远程存储库时,此Git警告消息是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

描述有点简洁。我只是在我的本地主分支上添加了一个文件,并将其推回到远程仓库。任何想法为什么会出现这种情况?

The description is a bit terse. I simply added a file on my local master branch and pushed it back to a remote repo. Any idea why this is coming up?


warning: updating the current branch
warning: Updating the currently checked out branch may cause confusion,
warning: as the index and work tree do not reflect changes that are in HEAD.
warning: As a result, you may see the changes you just pushed into it
warning: reverted when you run 'git diff' over there, and you may want
warning: to run 'git reset --hard' before starting to work to recover.
warning: 
warning: You can set 'receive.denyCurrentBranch' configuration variable to
warning: 'refuse' in the remote repository to forbid pushing into its
warning: current branch.
warning: To allow pushing into the current branch, you can set it to 'ignore';
warning: but this is not recommended unless you arranged to update its work
warning: tree to match what you pushed in some other way.
warning: 
warning: To squelch this message, you can set it to 'warn'.
warning: 
warning: Note that the default will change in a future version of git
warning: to refuse updating the current branch unless you have the
warning: configuration variable set to either 'ignore' or 'warn'.   


推荐答案

实际上,这意味着它几乎完全是这样说的:有人正在存储库中工作你正在推动,而且有人目前已经签出了你正在推送的完全相同的分支。

Actually, it means pretty much exactly what it says: somebody is working in the repository that you are pushing to, and that somebody has currently checked out the exact same branch that you are pushing to.

这很混乱,因为现在他认为他已经检查过在最新版本的分支中,实际上,您刚刚将分支更新为新版本。因此,当他现在运行 git commit 时,他的提交将基本上恢复您刚刚推送的所有提交。当他运行 git diff 时,即使他甚至没有改变任何东西,他也会看到与刚刚推送的内容相反的内容。

This is very confusing, because now he thinks that he has checked out the latest version of the branch, when, in fact, you have just updated the branch to a newer version. So, when he now runs git commit, his commit will essentially revert all the commits that you just pushed. And when he runs git diff he will see the opposite of everything you just pushed, even though he maybe hasn't even changed anything.

出于这个原因,推送到非裸仓库通常被认为是不好的做法;您只应推送到裸露的存储库,即没有附加工作副本的存储库。至少你应该确保你不会推送到当前签出的分支,但是通常你不应该把你的代码推到别人的仓库中,而应该让他们从你那里拉出来。

For that reason, it is generally considered bad practice to push to a non-bare repository; you should only ever push to bare repositories, i.e. repositories that do not have an attached working copy. At the very least you should make sure that you do not push to the currently checked-out branch, but generally you shouldn't just shove your code into someone else's repository, you should ask them to pull from you instead.

在某些特殊情况下,例如当您从Git存储库提供网站并希望通过推送网站来更新网站时,实际上推送到当前已检查的网站out分支,但是在这种情况下,你必须确保你已经安装了一个实际上更新检出工作副本的钩子,否则你的网站将永远不会被更新。

In some special cases, like when you are serving a website from a Git repository and you want to update the website by pushing to it, it actually makes sense to push to the currently checked-out branch, but in that case you must make sure that you have a hook installed that actually updates the checked-out working copy, otherwise your website will never be updated.

这篇关于将更改推送到远程存储库时,此Git警告消息是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆