将Git存储库移动到子文件夹

时间:2018-01-01 18:04:05

标签: wordpress git github version-control repository

我在我的Wordpress网站上使用Github。

目前它跟踪父Wordpress文件夹,它实质上跟踪所有内容。

enter image description here

我希望它只有一个只有主题的git,位于wp-content/themes/lighthouse

是否有一种简单的方法可以将此存储库仅作为主题而不是Wordpress中的所有内容?无需建立新的存储库?

2 个答案:

答案 0 :(得分:0)

如果你真的不想创建一个新的仓库,你只需删除其他文件夹,然后将新的(修剪过的)提交回到现有的仓库。
请注意,您可以保留过去提交中的其他文件夹历史记录。

" Detach (move) subdirectory into separate Git repository"中提及的技术实际上会创建一个新的仓库(一个只包含您想要保留的文件夹的历史记录)

答案 1 :(得分:0)

要将git repo移动到子文件夹wp-content/themes/lighthouse,同时保留子文件夹的历史记录,您可以参考以下步骤:

git clone <repo URL>
cd reponame
# checkout all the remote branches locally by git checkout branchname
git filter-branch --subdirectory-filter wp-content/themes/lighthouse -- --all
git push -f --all

现在git repo移动到子文件夹wp-content / themes / lighthouse并保留相关历史