从另一个分支的子目录更新一个分支的根目录

从另一个分支的子目录更新一个分支的根目录

本文介绍了从另一个分支的子目录更新一个分支的根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 github 上开发,我经常在我的主分支中维护一个 html/_site/ 子目录,我在那里为项目生成基于 Web 的文档.我想切换到我的 gh-pages 分支,并且 pull 这个 html 目录的内容到 gh-pages 分支的根目录,所以它会呈现为一个不错的 github 网站(它会在 username.github.com/repositoryname 处的 gh-pages 中自动呈现 html).执行此操作的最佳工作流程是什么?

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?

如果我还没有设置 gh-pages 分支,我可以分支,清除分支,然后复制 html 目录中的内容并快速,我有一个站点准备好出发.但我不确定以后如何最好地更新 gh-pages 分支.

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

现在我应该怎么做才能稍后更新 gh-pages 分支?听起来这可能涉及 子树合并 但我'我不太确定.

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.

推荐答案

开始你的 gh-pages 分支:

To start your gh-pages branch:

true | git mktree | xargs git commit-tree | xargs git branch gh-pages

要获取任何您想要的内容,请从 master 分支、read-tree 和 commit 中说 html 目录:

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

你就完成了.

后期添加:添加到 gh-pages 分支的顺序较短:

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

不需要刷新当前工作树

这篇关于从另一个分支的子目录更新一个分支的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 16:11