git 将本地主 * 推入 * github 上的 gh-pages 分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20411849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:25:48  来源:igfitidea点击:

push local master *into* gh-pages branch on github

gitgithubgithub-pages

提问by backspaces

I created a simple gh-pages branch on github and in my local repo. I used the auto page generator to create the 5 files it uses: images javascripts stylesheets index.html params.json

我在 github 和我的本地仓库中创建了一个简单的 gh-pages 分支。我使用自动页面生成器创建了它使用的 5 个文件:images javascripts stylesheets index.html params.json

I pulled this to my local repo and added js-markdown-extra.js to javascripts, and edited index.html to replace the "content" section with the compiled README.md created by the markdown library.

我将它拉到我的本地存储库并将 js-markdown-extra.js 添加到 javascripts,并编辑 index.html 以用 Markdown 库创建的编译后的 README.md 替换“内容”部分。

Putting in a dummy README.md showed it to work perfectly.

放入一个虚拟的 README.md 显示它可以完美运行。

I wantto then simply push my local master into(not onto) the remote gh-pages branch, without modifying the 5 website files.

然后我简单地将我的本地 master 推送到(而不是推送到)远程 gh-pages 分支,而不修改 5 个网站文件。

I haven't found a way to do this. I was told via http://oli.jp/2011/github-pages-workflow/that this would work: git push -f origin master:gh-pages

我还没有找到办法做到这一点。我通过http://oli.jp/2011/github-pages-workflow/被告知这会起作用:git push -f origin master:gh-pages

I tried this on a test repo and it failed, resulting in a 404 (pushing the local gh-pages made for the markdown trick fixed that)

我在测试仓库上尝试过这个,但失败了,结果是 404(推送为降价技巧制作的本地 gh-pages 修复了这个问题)

So isthere a way to push master into, as a subset of, gh-pages?

那么没有办法将 master作为 gh-pages 的一个子集推

Failing that, is there a simple way to merge the master into gh-pages locally without deleting the 5 website files?

如果没有,有没有一种简单的方法可以在不删除 5 个网站文件的情况下将 master 合并到本地的 gh-pages 中?

I know how to "mirror" all this stuff so the 5 files would be in the repo but I'd like to avoid that clutter.

我知道如何“镜像”所有这些东西,这样 5 个文件就会在 repo 中,但我想避免这种混乱。

回答by stellarhopper

From what I understand, you'd have to switch to your local copy of gh-pages. Merge in master, and then push gh-pages

据我了解,您必须切换到 gh-pages 的本地副本。合并到master,然后push gh-pages

git checkout gh-pages
git merge master
git push origin gh-pages

回答by Jed Schneider

If I understand you correctly it seems that you created the dummy Readme and the other files on your local master branch but intended to have them on the gh-pages branch. If thats the case, the safest option is to merge your master branch into the gh-pages branch (assuming you dont have other files on master you would rather not have on the gh-pages branch). The command suggested git push -f origin master:gh-pageswill push your local master branch to the gh-pages branch. I'm not really sure what you mean but into vs onto, as branch names are just pointers in git.

如果我理解正确,您似乎在本地 master 分支上创建了虚拟自述文件和其他文件,但打算将它们放在 gh-pages 分支上。如果是这种情况,最安全的选择是将您的 master 分支合并到 gh-pages 分支(假设您在 master 上没有其他文件,而您宁愿不在 gh-pages 分支上)。建议的命令git push -f origin master:gh-pages会将您本地的 master 分支推送到 gh-pages 分支。我不太确定你的意思,但进入 vs on,因为分支名称只是 git 中的指针。

回答by jamie

Here is a good writeup github pages workflowthat I used to understand how to interact between the master and gh-pages branches.

这是一篇很好的github pages 工作流程,我用来了解如何在 master 和 gh-pages 分支之间进行交互。

paul irish from google recommended it in the comments of another article- it had super clear examples.

来自谷歌的 paul irish 在另一篇文章的评论中推荐了它——它有非常清晰的例子。

回答by Eliran Malka

as an alternative approach, how about using a git subtreeto serve as your gh-pagesbranch?

作为替代方法,如何使用 git子树作为您的gh-pages分支?

git checkout master
git subtree push --prefix . origin gh-pages

according to the git-subtreedocs on the source code:

根据源代码上的git-subtree文档:

Subtrees allow subprojects to be included within a subdirectory of the main project, optionally including the subproject's entire history.

子树允许将子项目包含在主项目的子目录中,可选择包含子项目的整个历史。

in our case, we may be able to alias the same path (the root path; .) as a virtual copy of the master branch (i have not tested it, though).

在我们的例子中,我们可以将相同的路径(根路径;.)作为主分支的虚拟副本(不过我还没有测试过)。

by the way, i found out about subtrees after encountering this gist, by cobyism.

顺便说一句,在遇到这个要点后,我通过cobyism发现了子树。