Thursday, May 26, 2022

20220526 git move folders with their history to another repo

Main ref: https://mattsch.com/2015/06/19/move-directory-from-one-repository-to-another-preserving-history/

If there are multiple folders, we need to do thing differently.

  1. Source repo
    1. git remote rm origin
    2. git filter-branch --index-filter 'git rm --cached --ignore-unmatch -rf XXX' --prune-empty -f HEAD
      1. for all other folders or files
      2. for all subtrees, just do a clean up
  2. Dest repo
    1. git remote add <branch> <source repo directory>
    2. git checkout <branch>
    3. git checkout <Dest repo working branch>
    4. git merge develop --allow-unrelated-histories
    5. git push
    6. add back subtree
    7. git push
The assumption is that the directory names in the source repo remain the same in the dest repo.  If different, the commit history needs to change. 
  • Directory name and level manipulation shall be done at the Source repo side.  This shall greatly simplify the merge. 

No comments:

Post a Comment