git:从另一个子目录更新分支的根目录 [英] git: update the root directory of a branch from the subdirectory of another
问题描述
在github上开发,我经常在我的master分支中维护一个 html /
或 _site /
子目录基于网络的项目文件。我想切换到我的gh-pages分支,并将 html
目录中的内容< gh-pages
中的html呈现为 username.github。 COM / repositoryname
)。什么是最好的工作流程?
如果我还没有设置gh-pages分支,我可以分支,清除分支并复制 html
目录和presto的内容,我准备好了一个网站。但我不确定以后如何更新gh-pages分支。
git分支gh-pages
git checkout gh-pages
#删除文件我不需要从gh-pages分支
rm -rf data / man / R / README.md新闻名称描述demo /
#将文档移动到根目录
mv inst / doc / html / *。
#删除其余的
rm -rf inst /
git add *
git commit -a -mgh-pages文档
git push origin gh-pages
git checkout master
现在我该怎么做才能更新gh-pages分支?这听起来像这可能涉及子树合并,但我'我不太确定。
开始你的gh-pages分支:
true | git mktree | xargs git commit-tree | xargs git branch gh-pages
要获取任何你想要的东西,比如说master的html目录分支,读取树和提交:
git checkout gh-pages
git读取树master:html
git commit -m'gh-pages documentation'
git push origin gh-pages
git checkout master
,你就完成了。
延迟添加:添加到gh-pages分支的序列更短:
git commit-tree -p gh-pages -mmaster:html \
| xargs git update-ref refs / heads / gh-pages
不需要刷新当前工作树
Developing on github, I often maintain a html/
or _site/
subdirectory in my master branch where I generate web-based documentation for the project. I'd like to switch to my gh-pages branch and pull
just the contents of this html
directory into the root of the gh-pages branch, so it will render as a nice website through github (which automatically renders html in gh-pages
at username.github.com/repositoryname
). What is the best workflow to do this?
If I don't yet have the gh-pages branch set up, I can branch, clear the branch, and copy in the contents of the html
directory and presto, I have the a site ready to go. But I'm not sure how best to later update the gh-pages branch.
git branch gh-pages
git checkout gh-pages
# Remove files I don't need from the gh-pages branch
rm -rf data/ man/ R/ README.md NEWS NAMESPACE DESCRIPTION demo/
# move documentation to the root
mv inst/doc/html/* .
# remove the rest
rm -rf inst/
git add *
git commit -a -m "gh-pages documentation"
git push origin gh-pages
git checkout master
Now what should I do to update the gh-pages branch later? It sounds like this might involve subtree merging but I'm not quite sure.
To start your gh-pages branch:
true | git mktree | xargs git commit-tree | xargs git branch gh-pages
To fetch anything you want into it, say the html directory from the master branch, read-tree and commit:
git checkout gh-pages
git read-tree master:html
git commit -m'gh-pages documentation'
git push origin gh-pages
git checkout master
and you're done.
Late addition: there's a shorter sequence for adding to the gh-pages branch:
git commit-tree -p gh-pages -m "" master:html \
| xargs git update-ref refs/heads/gh-pages
which doesn't require flushing the current working tree
这篇关于git:从另一个子目录更新分支的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!