将 Jekyll 站点发布到 Git 存储库
每次我运行 Jekyll 时,它都会破坏目标文件夹的全部内容。问题是我的目标目录是一个小的 git 存储库,我用它来推送到我的实际服务器。有没有办法阻止 Jekyll 删除 Git 文件,这样我就不必生成内容然后复制它们?
Every time I run Jekyll it destroys the entire contents of the destination folder. The problem with this is that my destination directory is a small git repo from which I use to push to my actual server. Is there a way to stop Jekyll deleting the Git files so that I don't have to generate the contents then copy them over?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以:
GIT_WORK_TREE
变量,并将目标文件夹作为值换句话说,
.git
在工作树目录本身中不一定是必需的。它可以在其他地方,您的脚本可以通过
GIT_WORK_TREE
或通过--work-tree=
选项引用实际工作树。如果您的脚本是 Jenkyll 复制/删除文件的目标目录的一部分,您可以执行相反的操作,并使用选项。
GIT_DIR
变量或.git
实际所在位置。 code>--git-dir=要将新的
--work-dir
作为存储库的默认选项,您可以使用git-config --add core.worktree ../PATH/
,其中>PATH
- 相对于.git
的实际工作目录的路径。You could have:
GIT_WORK_TREE
variable with the destination folder as valueIn other words, a
.git
don't have to be necessary in the working tree directory itself.It can be elsewhere, and your script can refer to the actual working tree through
GIT_WORK_TREE
or through a--work-tree=<path>
option.If your script is part of the destination directory where Jenkyll copies/erases files, you can do the opposite, and mention where the
.git
actually is withGIT_DIR
variable or with--git-dir=<path>
option.To have new
--work-dir
as default options to your repo, you can usegit-config --add core.worktree ../PATH/
, wherePATH
- path to actual working directory relative to.git
.您看过 Jekyll wiki 的部署部分吗? - https://github.com/mojombo/jekyll/wiki/Deployment。它清楚地解释了 Jekyll 部署步骤。
为什么你要从目的地出发?那就不好了!从其他克隆推送它。
Have you had a look at the Deployment section of the Jekyll wiki? - https://github.com/mojombo/jekyll/wiki/Deployment. It clearly explains Jekyll deployment steps.
And why are you pushing from the destination? That is bad! Push it from some other clone.
我也想要这个设定发现这个拉取请求来修复 Jekyll,使其不删除 .git 目录:
https://github.com/mojombo/jekyll/pull/337
阅读我的评论,因为:
无论如何,我的 Jekyll 行现在显示为:
dest_files <<文件除非 file =~ /\/\.{1,2}$/ || file =~/\/\.git/
效果很好!我什至使用octopress(只需将您的deploy_dir更改为公共)并在Rakefile中注释掉以下几行:
现在您的公共目录(而不是_deploy目录)可以是您的github存储库来发布您的站点(分支或我的子模块)在我的例子中,
使用 public 和 _deploy 似乎毫无意义,但我很高兴听到分割 public 和 _deploy 目录的其他原因 - 除此之外Jekyll 删除 .git 目录。 (我通读了 octopress 的完整提交历史,但找不到任何解释为什么这样做)
I also want this setup. Found this pull request to fix Jekyll, making it not delete the .git dir:
https://github.com/mojombo/jekyll/pull/337
Read my comment there, as:
Anyway, my Jekyll line now reads:
dest_files << file unless file =~ /\/\.{1,2}$/ || file =~/\/\.git/
Works great! I'm even using octopress (just change your deploy_dir to be public) and comment out the following lines in Rakefile:
Now your public dir (instead of _deploy dir) can be your github repo to publish your site (submodule of a branch or my parent repo in my case)
Seems senseless to have public and _deploy with octopress, but I'm happy to hear other reasons why to split public and _deploy dirs - besides Jekyll deleting the .git dir. (I read through the full commit history of octopress, but couldn't find any explanation for why its done this way)
我实际使用
并解决了这个问题。
I actually used
and sovled this problem.
@manojlds,我不确定我是否理解,TPW 的默认 _config.yml (我已自定义)将 _site 目录的位置显示为“.”,位于博客目录内,其中还包含 Git 存储库。有没有办法移动这个目录,这样它就不会把文件散得到处都是?我想我在这里遗漏了一些东西,因为要么 Jekyll 拒绝生成任何东西,要么发生上述情况,我必须清理留下的烂摊子。
对于 _site 可以(或应该)位于何处,我们是否有最佳实践?
编辑:看看它,我实际上看到以下内容:
来源:。
目的地:./_site
终端找不到 jekyll gem(通过 RVM 安装)的事实可能是我的问题的原因,而不是 _site 的位置。
@manojlds, I'm not sure I understand, TPW's default _config.yml (Which I've customized) shows the location of the _site directory as ".", inside of the blog directory which also contains the Git repo. Is there a way to move this directory so that it doesn't spew files all over the place? I think I'm missing something here because either Jekyll refuses to generate anything or the above scenario happens and I have to clean up the mess that's left behind.
Do we have a best practice for where _site can (or should) be located?
Edit: Looking at it, I actually see the following:
source: .
destination: ./_site
The fact that Terminal can't find the jekyll gem (installed via RVM) is probably the cause of my problem rather than the location of _site.