我有一个问题
情况基于gh-pages https://pages.github.com/
我的项目使用预处理器和其他困难的人员,因此,我的项目结构如下所示:
主分支
./-|
/src
/node_modules
/public-|
/js
/css
/etc
index.html
/etc
package.json
etc
所有代码源在src文件夹,编译到public folder.
public文件夹也在 .gitignore 中
我想将公共文件夹中的所有文件提交到 gh-pages 分支中。是否可以?如果是,该怎么做?这是我的一个结构gh-pages branch
gh-pages 分支
./-|
/js
/css
/assets
index.html
我认为运行 grunt/gulp 任务并将结果提交到另一个分支会很棒。
我有两个脚本可以做到这一点。在我的情况下,文档来源位于.
(当然,相对于脚本运行的位置),生成的文档位于_build/html
,然后我发出命令
touch _build/html/.nojekyll # disable GitHub's Jekyll page generator
./commit-to-gh-pages.sh _build/html
where commit-to-gh-pages.sh
is
#! /bin/sh
# Commit the generated HTML pages to the branch gh-pages.
# Will not push them to GitHub.
set -e -v
treehash=$(./hash-tree.py "${1:-_build/html}")
parent=$(git rev-parse gh-pages)
msg="Regenerated docs for $(git rev-parse HEAD)"
commithash=$(echo "$msg" | git commit-tree $treehash -p $parent)
echo "Updating gh-pages to $commithash"
git update-ref refs/heads/gh-pages "$commithash"
这会写入目录_build/html
到 Git 索引,创建一个以该目录树为其内容的提交对象,并将该提交对象写入gh-pages
将该分支的先前状态作为父分支。
棘手的部分是hash-tree.py
脚本,它扩展了git hash-object
命令到目录树。我不会复制粘贴,但你可以得到它here https://github.com/NLeSC/xtas/blob/master/doc/hash-tree.py。 (如果有人知道更优雅的方法,请告诉我。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)