将 gh-pages 与 master 的最新提交保持同步 [英] Bring gh-pages up to date with the latest commit of master
问题描述
我将 SourceTree 与 Github 存储库结合使用,用于项目的版本控制.有一段时间,我一直在使用 master
来提交所有新的更改,但时不时地,我希望 gh-pages
分支快进到最新的master
的提交,以便我可以使用生产中的页面更新实时页面(通常在主要更新完成时).
我已经尝试过重新定位,正如另一篇 SO 帖子所建议的那样,但这使问题变得更糟,因为 SourceTree 让我手动选择我想要的更改并且重新定位需要一些时间,特别是考虑到上次更新之间的提交量gh-pages
.在一个项目中成功变基后,我基本上可以在需要时将 gh-pages
分支同步到 master
并且所有中间版本都会自动提交(我无法重现虽然在另一个存储库中的行为相同).但是,我想要的是获取最后一次提交并覆盖所有文件.为此,我通常只是将 master
分支上的整个文件夹复制到另一个位置,然后切换到 gh-pages
并手动覆盖所有文件.不过,这是次优的,对于大型项目来说可能会带来真正的问题.
所以,我想要和需要的是通过 SourceTree 或脚本自动执行此过程.
TL;DR:我需要一种半自动将 gh-pages
更新到最新的 master
提交的方法,这将覆盖所有master
中的文件,无需重新定位,然后将它们推送到 Github 存储库.
但是,我想要的是获取最后一次提交并覆盖所有文件.
你应该:
- 使用
--ours
选项将gh-pages
合并到master
(因此 master 实际上未受影响). - 将 master 合并到
gh-pages
(这意味着gh-pages
快进到master
并变得相同)
所以:
git checkout mastergit merge --ours gh-pagesgit checkout gh-pagesgit合并大师
<小时>
不要忘记,从几天前开始,您不必再维护 gh-pages
分支.
I am using SourceTree in combination with a Github repository for version control for a project. For a while, I've been using master
to commit all new changes, but every now and then, I want the gh-pages
branch to fast-forward to the latest commit of master
, so that I can update the live page with the page I have in production (usually when a major update is finished).
I have tried rebasing, as another SO post suggested, but this made the problem even worse, as SourceTree had me manually choose what changes I wanted and the rebasing took a little while especially considering the amount of commits between the last update of gh-pages
. After successfully rebasing in one project, I could basically sync the gh-pages
branch to master
whenever I desired and all in-between versions would commit automatically (I could not reproduce the same behavior in another repository though). However, what I want is to get the last commit and overwrite all files. To do this, I usually just copy the whole folder while on master
branch to another location, then switch to gh-pages
and overwrite all files manually. This is sub-optimal, though and can get really problematic for larger projects.
So, what I want and need is to automate this procedure, either through SourceTree or via a script.
TL;DR: I need a way to update gh-pages
to the latest master
commit semi-automatically, which will overwrite all files with the ones in master
without rebasing and will then push them to the Github repository.
However, what I want is to get the last commit and overwrite all files.
You should:
- merge
gh-pages
tomaster
with the--ours
option (so master is actually untouched). - merge master to
gh-pages
(which meansgh-pages
fast-forwards tomaster
and becomes identical)
So:
git checkout master
git merge --ours gh-pages
git checkout gh-pages
git merge master
Don't forget though that since a few days ago, you don't have to maintain a gh-pages
branch anymore.
Simpler GitHub Pages publishing now allows to keep your page files in a subfolder of the same branch (no more gh-pages
needed):
这篇关于将 gh-pages 与 master 的最新提交保持同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!