0

I have a requirement to move few files from one repo to another repo with files commit history. Both repos are completely different structure.

Repo 2 is belongs to another team.

Repo 1 - /folder1/subfolder1/text.txt

TO

Repo 2 - folder1/test.txt

Do we have a way to do this ?.

  • 3
    Does this answer your question? [How to move files from one git repo to another (not a clone), preserving history](https://stackoverflow.com/questions/1365541/how-to-move-files-from-one-git-repo-to-another-not-a-clone-preserving-history) – Maulik Sakhida Aug 13 '21 at 18:49
  • @MaulikSakhida - I guess my use case different since my both repos structure different – Surz Kumar Ve Aug 13 '21 at 18:56
  • Does this answer your question? [git move directory to another repository while keeping the history](https://stackoverflow.com/questions/41811986/git-move-directory-to-another-repository-while-keeping-the-history) – Joe Aug 14 '21 at 00:57

1 Answers1

0

You can adapt the answer in How to move files from one git repo to another (not a clone), preserving history with e.g.

git filter-branch --subdirectory-filter sourcedir/subdir \
        --index-filter '
                git read-tree --empty
                git ls-tree -r $GIT_COMMIT:sourcedir/subdir \
                | sed s,\\t,\\tdestdir/, \
                | git update-index --index-info
        '

and add whatever other selection/munging instructions you want to the sed, like put "/.txt$/!d;" on the front of it so you drop everything but the .txt files, or whatever else you want to do to the path names.

jthill
  • 55,082
  • 5
  • 77
  • 137