2013-10-07 18 views
0

我有一個包含一個WordPress站點一個Git倉庫,根文件夾看起來像這樣:調整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

由於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回購只包含你的主題現在運行的混帳東西。

然後,提取檔案,把你唯一的主題回購在那裏:

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. 
+0

感謝。它看起來像你的命令將物理移動文件,這不會破壞要求#2?我也正確地認爲每個文件都需要單獨列出,即'license.txt readme.html'等。 – AlecRust

+0

這將確實打破#2,但是真的沒有辦法做到這一點。 git中的文件與磁盤上的文件是分開的。如何正確地獲取磁盤上的文件與git,vcs和whatnot無關,只需複製正確的東西即可。 – berkes

+0

太好了,非常感謝。 – AlecRust