`receive.denyCurrentBranch=updateInstead` 如何与索引交互?

How does `receive.denyCurrentBranch=updateInstead` interact with the Index?

receive.denyCurrentBranch config option 控制推送到正在结帐的回购分支时会发生什么。

默认情况下,它会拒绝它(这就是为什么您通常只推送到没有结帐分支的裸仓库)。

可以通过ignorewarn禁用它。

另一种选择是updateInstead

这样做的是,如果HEAD和工作目录相同,并且被推送的分支是HEAD,那么工作目录和分支/HEAD都是同时更新。

如果工作目录与HEAD不同,推送将被拒绝。
这对于推送到网络服务器很有用,for example.

我的问题是,此选项是否与 Index 交互?

索引更新了吗?如果 HEAD 和工作目录匹配,但 Index 不匹配怎么办?

Is the Index updated? What if HEAD and the working directory match, but not Index?

Commit 0855331 (git 2.4.0-rc0, Dec. 2014)说清楚:

When receive.denyCurrentBranch is set to updateInstead, a push that tries to update the branch that is currently checked out is accepted only when the index and the working tree exactly matches the currently checked out commit, in which case the index and the working tree are updated to match the pushed commit.
Otherwise the push is refused.

虽然同一个提交引入了 push-to-checkout 钩子。

This hook can be used to customize this "push-to-deploy" logic.
The hook receives the commit with which the tip of the current branch is going to be updated, and can decide what kind of local changes are acceptable and how to update the index and the working tree to match the updated tip of the current branch.

这为索引提供了一些灵活性。


Commit 1a51b52, git 2.4.0-rc2, Apr 2015再说一遍:

Setting receive.denycurrentbranch to updateinstead and pushing into the current branch, when the working tree and the index is truly clean, is supposed to reset the working tree and the index to match the tree of the pushed commit.