为什么checkout -f放入接收后挂钩是正确的选择? [英] why is checkout -f the right thing to put in a post-receive hook?
问题描述
我在Dreamhost上拥有一个帐户,他们对如何使用Git跟踪自定义WordPress主题中的文件进行了说明.他们的说明位于 https://help .dreamhost.com/hc/zh-CN/articles/227816388-Using-Git-with-DreamPress ,与许多其他建议相同的网站相同.例如, http://git-memo.readthedocs.io/en/latest /deploy.html
I have an account on Dreamhost and they have instructions on using Git to track files in a custom WordPress theme. Their instructions, at, https://help.dreamhost.com/hc/en-us/articles/227816388-Using-Git-with-DreamPress, are the same as many other websites that suggest same. For example, http://git-memo.readthedocs.io/en/latest/deploy.html
您将可执行脚本放入裸仓库的hooks/post-receive
目录中,它称为git"checkout -f".这是示例脚本
You put in an executable script in a bare repo's hooks/post-receive
directory and it calls a git "checkout -f". Here is the example script
#!/bin/sh
GIT_WORK_TREE=/home/user/theme-directory git checkout -f
这是我不明白的地方.为什么选择"checkout -f"?这只会更改要跟踪的分支的名称,而不会使其更新.是否应该拉扯(或获取)新内容?结帐功能是否比我理解的要强?
Here is what I don't understand. Why "checkout -f"? That only changes the name of the branch being tracked, it does not bring it up to date. Shouldn't there be a pull (or fetch) the new content? Does checkout have more power than I undersand?
推荐答案
post-receive
是因此无需拉动:客户端会推送一些内容,然后在服务器上将其签出.
So no need for a pull: the client pushes some content, which is then checked out on the server.
为什么要结帐-f"?
Why "checkout -f"?
首先,"checkout -f
"实际上是checkout -f @
或checkout -f HEAD
:它检查出当前的HEAD(在推送之后).
First, "checkout -f
" is actually checkout -f @
, or checkout -f HEAD
: it checks out whatever HEAD is now (after the push).
第二, --force
选项可确保即使索引或工作树与HEAD有所不同,切换分支也会成功(因为推送刚刚更改为HEAD,所以它会成功)
Second, the --force
option ensures that switching branch succeeds even if the index or working tree differs from HEAD (which it will, since the push just changed said HEAD)
但是我会尝试
GIT_WORK_TREE=/home/user/theme-directory git checkout -f -- .
即:指定路径规范,它将通过替换索引或(通常是一个提交,这里是:HEAD,在推送后刚刚更改)的内容来覆盖工作树中的路径.
That is: specifying a pathspec, which will overwrite paths in the working tree by replacing with the contents in the index or in the (most often a commit, here: HEAD, which just changed after the push).
这篇关于为什么checkout -f放入接收后挂钩是正确的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!