繁体   English   中英

如何使用Github Pages分支在存储库中正确提交

[英]How to properly commit in repository with Github Pages branch

我有一个问题

基于gh页面的情况

我的项目使用预处理器和另一个困难的员工,因此,我的项目结构如下所示:

主分公司

./-|
   /src
   /node_modules
   /public-|
       /js
       /css
       /etc
       index.html           
   /etc
   package.json 
   etc

src文件夹中的所有代码源,编译成公共文件夹。
公共文件夹也在.gitignore中
我想将我公共文件夹中的所有文件提交到gh-pages分支。 可能吗? 如果是的话,怎么做? 这是我的gh-pages分支的结构

gh-pages分支

 ./-|
    /js
    /css
    /assets
    index.html    

我认为运行grunt / gulp任务并将结果提交到另一个分支会很棒。

我有一对脚本就是这样做的。 在我的情况下,doc来源是. (当然,相对于运行脚本的位置),生成的文档在_build/html ,我发出命令

touch _build/html/.nojekyll    # disable GitHub's Jekyll page generator
./commit-to-gh-pages.sh _build/html

commit-to-gh-pages.sh在哪里

#! /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命令扩展到目录树。 我不会复制粘贴它,但你可以在这里得到它。 (如果有人知道更优雅的方式,请告诉我。)

我有很好的经验,将repo克隆到自己的子目录中并查看不同的分支:对于你的情况,像

# add public to .gitignore
git clone . public
cd public
git checkout --orphan gh-pages
git reset --hard
git commit --allow-empty "initial"

让你开始吧 请参阅http://krlmlr.github.io/git-subbranch进行撰写。

如果你有git版本> 1.7.11,你可以尝试使用git subtree 我自己几乎无法理解细节,所以我不会尝试解释它,但是Hugo网站建设者有一个教程。 相关部分从头部配置git工作流开始

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM