簡體   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