如何正确提交与Github Pages分支的存储库 [英] How to properly commit in repository with Github Pages branch

查看:165
本文介绍了如何正确提交与Github Pages分支的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题



根据 gh我的项目使用预处理器和其他困难的员工,因此,我的项目结构如下所示:



master branch

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

src 文件夹中的所有代码资源,编译为公共文件夹。<
公共文件夹也在.gitignore

中我想将公用文件夹中的所有文件提交到gh-pages分支。可能吗?如果是的话,该怎么做?这是 gh-pages 分支的结构



gh-pages分支

  ./- | 
/ js
/ css
/资产
index.html

我认为运行grunt / gulp任务并将结果提交到另一个分支将会很好。 一对脚本完全做到这一点。在我的情况下,doc源文件位于(相对于当前运行脚本的位置),生成的文档位于 _build / html ,然后发出命令

  touch _build / html / .nojekyll#禁用GitHub的Jekyll页面生成器
./commit-to-gh-pages.sh _build / html

其中 commit-to-gh-pages.sh

 #! / bin / sh 

#将生成的HTML页面提交给分支gh页面。
#不会将它们推送到GitHub。

set -e -v

treehash = $(./ hash-tree.py$ {1:-_ build / html})
parent = $(git rev-parse gh-pages)
$ b msg =重新生成文档$(git rev-parse HEAD)
commithash = $(echo$ msg| git commit- tree $ treehash -p $ parent)
echo将gh-pages更新为$ commithash
git update-ref refs / heads / gh-pages$ commithash

这会将目录 _build / html 写入Git索引,创建一个提交对象具有此目录树作为其内容,并将提交对象写入 gh-pages 分支中,并将该分支的以前状态作为父项。



棘手的部分是 hash-tree.py 脚本,它扩展了 git hash-object 命令到目录树。我不会复制粘贴它,但您可以此处。 (如果有人知道更优雅的做法,请告诉我。)


i've got a question

Situation based on gh-pages

My project uses preprocessors and another difficult staff, so, my project stucture looks as follows:

master branch

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

all code sources in src folder, compiled - into public folder.
public folder also in .gitignore
I would like to commit all files in my public folder into gh-pages branch. Is it possible? If yes, how to do this? This is a structure of my gh-pages branch

gh-pages branch

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

I think it will be great to run grunt/gulp tasks and commit result into another branch.

解决方案

I have a pair of scripts that do exactly this. In my situation, doc sources are in . (relative to where the scripts are run, of course), generated documentation is in _build/html, and I issue the commands

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"

This writes the directory _build/html to the Git index, makes a commit object that has exactly this directory tree as its contents, and writes the commit object to the gh-pages branch with the previous state of that branch as the parent.

The tricky part is the hash-tree.py script, which extends the git hash-object command to directory trees. I won't copy-paste it, but you can get it here. (If anyone knows a more elegant way to do this, please tell me.)

这篇关于如何正确提交与Github Pages分支的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆