Git Config中receive.denyCurrentBranch做了什么?

24
May

Git Config中receive.denyCurrentBranch做了什么?

官网的解答

receive.denyCurrentBranch If set to true or "refuse", git-receive-pack
will deny a ref update to the currently checked out branch of a
non-bare repository. Such a push is potentially dangerous because it
brings the HEAD out of sync with the index and working tree. If set to
"warn", print a warning of such a push to stderr, but allow the push
to proceed. If set to false or "ignore", allow such pushes with no
message. Defaults to "refuse".

Another option is "updateInstead" which will update the working tree
if pushing into the current branch. This option is intended for
synchronizing working directories when one side is not easily
accessible via interactive ssh (e.g. a live web site, hence the
requirement that the working directory be clean). This mode also comes
in handy when developing inside a VM to test and fix code on different
Operating Systems.

这个config是决定 当你Push到一个非bare的远程库的正处于切换状态下分支时的行为。

设置为true或refuse时,会拒绝你的push并且发出几行警告消息
设置为warn时,会接受你的push并且发出几行警告消息
设置为false或ignore时会接受你的push且不发出警告

后两种虽然接受了push,但并没有直接反映在工作目录(working tree)上,你需要输入

git reset --hard

或者切换到其他分支再切换回来,才能刷新文件

设置为updateInstead时,会接受push并直接更新工作目录
但如果工作目录相对HEAD指针有更新,则会拒绝push
注意只有git 版本2.5以后才添加updateInstead. 请升级后再使用

添加新评论