2013-10-27 37 views
1

我有內容的Git倉庫答:git的子樹到同一項目的幾個地點

<shared files dir>/ 
     sharedFile1 
     sharedFile2 

而且我還有其他的git庫B有2個項目,他們每個人都有使用共享文件從庫A.這樣的文件結構將類似於此:

Project_X 
    <shared files dir>/ 
     sharedFile1 
     sharedFile2 
    <project X dirs> 

Project_Y 
    <shared files dir>/ 
     sharedFile1 
     sharedFile2 
    <project Y dirs> 

我想只有在存儲庫中進行更新的共享文件,我需要讓project_X和Project_Y輕鬆獲得這些更新。

實際上,符號鏈接可能是我需要的確切解決方案,但不幸的是,我使用的文件系統不支持它。

Git子樹也看起來是合適的解決方案,但問題是我找不到如何將同一分支的子樹合併到同一個存儲庫中的2個位置。我成功創建的文件結構,我需要:

git read-tree --prefix=Project_X/shared_files_dir/ -u shared_remote_branch 
git read-tree --prefix=Project_Y/shared_files_dir/ -u shared_remote_branch 

創建所需的filestructure(正是我在這個問題上所描述的),而是試圖合併更新帶給我的改變只是爲了我最後創建的子樹:只有

git merge --squash -s subtree --no-commit shared_remote_branch 

更新Project_Y/shared_files_dir /,而不是Project_X/shared_files_dir /從shared_remote_branch的變化。

我會很感激任何想法。如何從一個分支合併子樹到2個位置(Project_X/shared_files_dir /)和(Project_Y/shared_files_dir /)或如何使它在任何其他方法

回答

0

由於git1.8.2,你可以註冊一個submodule作爲following the latest commits of a given branch

因此,我建議這種方法在樹之一,因爲它允許:

  • 維護單獨的歷史記錄shared_files回購
  • 輕鬆地更新上次提交的一個分支

    git submodule update --remote 
    

你甚至可以convert an existing submodule in order to have it trakc the latest of a branch


OP選擇了simpler solution

我決定用一種變通方法:

  • 管理單獨的回購和共享模塊
  • 添加post-checkout鉤我的主要回購將把這些共享文件從共享回購站複製到主回購站。

我們是一個小團隊,所以這種方法是最簡單的爲我們

+0

謝謝您的回答。我不想使用子模塊,因爲網上有很多關於它們的問題(例如,在執行git子模塊更新時丟失了更改)。所以我想知道是否有更多的解決方案.... – user2924714

+0

@ user2924714我明白,但我一直在使用子模塊數月(如我的項目中:https://github.com/VonC/compileEverything/blob/master/ .gitmodules#L10-L13,其中子模塊Semantic-UI遵循'master'),並且在最近版本的git中,所有這些問題都已得到解決或嚴重緩解。 – VonC

+0

試圖使用子模塊,我仍然看到這是一個開銷,並有太多的錯誤選擇。你知道是否有可能使用子樹來完成它? (請參閱原始問題:我沒有將同一分支的子樹合併到同一個存儲庫中的2個位置,我成功創建了我需要的文件結構: git read-tree --prefix = Project_X/shared_files_dir/-u shared_remote_branch git read -tree --prefix = Project_Y/shared_files_dir/-u shared_remote_branch 但是:git merge --squash -s子樹 - 無提交shared_remote_branch 只更新Project_Y/shared_files_dir,不能同時更新 – user2924714

相關問題