3 回答

TA貢獻1963條經驗 獲得超6個贊
克隆并保留所有這些額外分支和提交的簡單方法:
1-確保您具有此git別名
git config --global alias.clone-branches '! git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout -t'
2-克隆遙控器,拉出所有分支,更改遙控器,過濾目錄,按入
git clone [email protected]:user/existing-repo.git new-repo
cd new-repo
git clone-branches
git remote rm origin
git remote add origin [email protected]:user/new-repo.git
git remote -v
git filter-branch --subdirectory-filter my_directory/ -- --all
git push --all
git push --tags

TA貢獻1772條經驗 獲得超5個贊
GabLeRoux的解決方案效果很好,除非您使用git lfs該文件,并且在要分離的目錄下有大文件。在這種情況下,在第3步之后,所有大文件都將保留為指針文件,而不是實際文件。我猜可能是由于.gitattributes文件在過濾器分支過程中被刪除了。
意識到這一點,我發現以下解決方案適用于我:
cp .gitattributes .git/info/attributes
將.gitattributes哪個git lfs用于跟蹤大文件的文件復制到.git/目錄中,以避免被刪除。
過濾分支完成后,.gitattributes如果您仍要對新存儲庫使用git lfs,請不要忘記放回:
mv .git/info/attributes .gitattributes
git add .gitattributes
git commit -m 'added back .gitattributes'
- 3 回答
- 0 關注
- 689 瀏覽
添加回答
舉報