I am currently cleaning up some git repos. Current status:
repo_A->Content_A
repo_B->Content_B
The new planned status is to have a clean repo, with A and B (names different from the original repos) as subdirs and in these subdirs the original content:
new_repo->A->Content_A
new_repo->B->Content_B
I want to keep the history on all the files Content_A and Content_B and as other software is accessing the history, using the --follow while using the log command is not really an option.
So far I tried a lot of things, subtree and submodules is not really fitting my use case either. The most promising solution I found and followed was given in this answer: https://stackoverflow.com/a/10548919
I also included the added points for the subdir part, but in the end, I end up with all the files of repo_A not in new_repo->A-> but still in new_repo->. Moving the files in a subdir then loses the history (without using --follow). I will give you my workflow, that is adapted from the answer mentioned above. I work in the Windows PowerShell, all repos are freshly cloned in the local directories.
cd path\to\dir\that\contains\all\the\repos
cd .\repo_A\
git filter-repo --to-subdirectory-filter A
cd ..\new_repo\
git remote add A ..\repo_A\
git fetch A --tags
git merge --allow-unrelated-histories A/master
git remote remove A
The comments to the mentioned answer and als the cited merge of Rubygems and Bundler seem to end up in a subdirectory, but my files end up directly in \new_repo\ and not in \new_repo\A\ (at least the history is fine). Only big difference in comparison to the Rubygems/Bundler-Merge-Output.txt is, that in my case, the filter-repo has no output at all, it starts and stops after one second without feedback.
What do I do wrong?
you are on the right track!
All you need to do is install git filter-repo
. it is not part of git, you have to install it separately.
Link for repo incase you want to install manually - https://github.com/newren/git-filter-repo)
Install command for Debian linux,
sudo apt install git-filter-repo
Install command for mac,
brew install git-filter-repo
------ update from submitter ------
In the git filter-repo code, the top line (shebang) was set to #!/usr/bin/env python3
. My windows environment only recognise python
and not python3
.
Two option to fix:
Option 1: Changing the shebang to #!/usr/bin/env python
in filter-repo code.
Option 2: creating a link to python3 in windows. Please refer this post, many options discussed -> https://superuser.com/questions/1576758/how-do-i-alias-python3-on-windows
Example:
I tested it after installing git-filter-repo
. It works like charm!
sample output:
project-a % git filter-repo --to-subdirectory-filter project-a
Parsed xxx commits
New history written in 0.08 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
Updating files: 100% (1052/1052), done.
HEAD is now at d675bxxx 55xx 7 modification to add validations for all scenarios
Enumerating objects: 1952, done.
Counting objects: 100% (1952/1952), done.
Delta compression using up to 10 threads
Compressing objects: 100% (668/668), done.
Writing objects: 100% (1952/1952), done.
Total 1952 (delta 904), reused 1952 (delta 904), pack-reused 0
Completely finished after 1.60 seconds.
project-a %