问题描述
描述有点简短.我只是在我的本地 master 分支上添加了一个文件并将其推送回远程仓库.知道为什么会出现这种情况吗?
警告:更新当前分支警告:更新当前签出的分支可能会导致混乱,警告:因为索引和工作树不反映 HEAD 中的更改.警告:结果,您可能会看到您刚刚推入的更改警告:当你在那里运行git diff"时恢复,你可能想要警告:在开始恢复之前运行git reset --hard".警告:警告:您可以将receive.denyCurrentBranch"配置变量设置为警告:远程存储库中的拒绝"禁止推送到其警告:当前分支.警告:要允许推入当前分支,您可以将其设置为忽略";警告:但不建议这样做,除非您安排更新其工作警告:树以匹配您以其他方式推送的内容.警告:警告:要压制此消息,您可以将其设置为警告".警告:警告:请注意,默认值将在未来版本的 git 中更改警告:拒绝更新当前分支,除非你有警告:配置变量设置为忽略"或警告".实际上,这与它所说的差不多:有人正在您推送到的存储库中工作,并且有人当前已签出完全相同的您要推送到的分支.
这很令人困惑,因为现在他们认为他们已经检查了分支的最新版本,而实际上,您刚刚将分支更新到了较新的版本.因此,当他们现在运行 git commit
时,他们的 提交基本上会还原您刚刚推送的所有提交.当他们运行 git diff
时,他们会看到与您刚刚推送的所有内容相反的内容,即使他们可能甚至没有更改任何内容.
因此,推送到非裸存储库通常被认为是不好的做法;您应该只推送到裸存储库,即没有附加工作副本的存储库.至少你应该确保你没有推送到当前签出的分支,但通常你不应该只是将你的代码推送到其他人的存储库中,你应该让他们从你那里拉取.
在某些特殊情况下,例如当您从 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.
This is very confusing, because now they think that they have checked out the latest version of the branch, when, in fact, you have just updated the branch to a newer version. So, when they now run git commit
, their commit will essentially revert all the commits that you just pushed. And when they run git diff
they will see the opposite of everything you just pushed, even though they maybe havn'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.
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 警告消息是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!