调整WordPress站点git存储库位置

时间:2013-10-07 09:29:14

标签: wordpress git version-control github

我有一个包含WordPress站点的git存储库,根文件夹如下所示:

/wp-admin
/wp-content
/wp-includes
index.php
license.txt
readme.html
wp-activate.php
wp-blog-header.php
wp-comments-post.php
wp-config-sample.php
wp-cron.php
wp-links-opml.php
wp-load.php
wp-login.php
wp-mail.php
wp-settings.php
wp-signup.php
wp-trackback.php
xmlrpc.php

但是,/wp-content/themes/<theme-name>/中的主题文件夹是我需要在此git存储库中控制版本的唯一文件夹。我希望这个存储库的根文件夹只显示这个主题文件夹的内容。

然而:

  • 我不想丢失任何提交历史记录
  • 我希望保持文件不变,只需更改git存储库的位置

1 个答案:

答案 0 :(得分:1)

由于git不会跟踪文件,也不会跟踪内容,因此您可以保存以移动文件:

git rm *php license.txt readme.html /wp-admin /wp-includes -r
git mv /wp-content/themes/<theme-name>/* .
git rm /wp-content/ -r
git commit

这就是全部。你会看到你的历史仍然存在,但你的根现在是主题。

关于git的好处是,你的存储库是自包含的。所以,如果你想首先尝试这个,而不是有超出你的git技能的风险,你可以简单地cp /path/to/project/root /backup/project并在/backup/project中玩游戏。显然你应该小心不要从那里推动变化。另一个更充分的方法是创建一个分支并在该分支中玩游戏,但我的经验是,那些不太熟悉Git的人,有一种更难管理的方法,然后是“沙盒副本”。

除了git部分之外,您还要提到结构的其余部分。要做到这一点:

进行备份(在项目内部,在其他任何事情之前):

git archive HEAD > /tmp/my_project.tar

现在运行上面提到的git东西,即让你的git-repo只包含你的主题。

然后,提取存档并将仅限主题的存档放在那里:

cd ..
mv <project-name>/ <theme_name>/ #your repo is now in a folder after the name of the theme
mkdir <project-name>/
tar -xf /tmp/my_project.tar <project-name>/ #extract the backup in the project-name folder.
rm -rf <project-name>/wp-content/themes/<theme-name>/ #remove the old theme
mv <theme-name>/ <project-name>/wp-content/themes/ # and move the git-repo with the theme in place of the old theme.