繁体   English   中英

Git:如何将gh-pages分支的内容移动到保存历史记录的docs /目录?

[英]Git: How to move contents of gh-pages branch to docs/ directory preserving history?

所以github最近实现了一个功能来使用masterdocs/目录而不是gh-pages 这对某些用例很有用,例如我的用例。

该场景是一个带有mastergh-pages分支的git repo(执行github页面的“旧”方式),我想将gh-pages分支中的所有内容移动到masterdocs/目录(“new” “做github页面的方式)。

我知道我可以使用git checkout master; git checkout gh-pages -- docs git checkout master; git checkout gh-pages -- docs ,但这将从gh-pages文件中删除历史记录,这是不受欢迎的。

我用git subtreegit filter-branch ,没有成功。

所以问题是: 是否有一个神奇的单行git命令将另一个分支的内容移动到子目录中,同时保留历史记录?

git subtrees是完美的。 你提到你“摆弄”他们,但你试过:

git subtree add --prefix=docs origin gh-pages

看看我的docs-subtree分支

我不知道是否有单行命令,但您可以尝试使用rebase,然后将其合并到master中

git checkout gh-pages
git rebase master
git checkout master
git merge --no-ff gh-pages

我没有找到任何神奇的单行,但做一个git merge (感谢@Wikiti鼓励我再次尝试该选项)似乎工作。

我遵循的最后一个方法并不漂亮,并涉及多次运行git reset

这并不完美,我鼓励任何git专家或gitlab员工提出更好的解决方案。 希望它能帮助其他人试图摆脱gh-pages分支,这就是我这样做的方式:

git checkout master
git checkout -b master-docs
git merge gh-pages

# Reset the "master" files so that files deleted are left untouched by the merge
git reset src/
git checkout src/
git reset any-other-master-files
git checkout any-other-master-files

# Manually edit any conflicts, e.g. in .gitignore (with your favourite editor)
vi .gitignore
git add .gitignore
vi any-other-conflicting-files
git add any-other-conflicting-files

# Move the "gh-pages" files into "docs/" directory
mkdir docs
git mv *.md docs/
git mv *.html docs/
git mv _posts docs/
git mv _layout docs/
git mv any-other-gh-pages-files docs/

# Check that everything looks OK, there should be only files added to docs/
# If not, go through last steps again
git status

# Confirm the merge
git commit

# Push to origin
git push -u master-docs

# Go to github, make a pull req from master-docs to master for peer review

结果看起来不错

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM