I have a project with the following structure:
.
└── maindir
├── subdir1
└── subdir2
I started the project by setting a git repo in both subdir1
and subdir2
. The project has grown bigger and now I had to create a parent dir maindir
and created a git repo in it too. However now it seems that the change made in subdir1
and subdir2
are not tracked by the git repo of maindir
. Moreover, for simplicity reason, I want to merge all the commit info of all the git repos into one single git repo, namely the one of maindir
. How can I do that?
EDIT 1
So I tried the answer of the link (Git: Combining two independent repos to one without losing the history) posted in the comment and got the following output. It seems to be more complicated than in the other SO question. What shall I do next?
$ git pull subdir1
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 58 (delta 25), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (58/58), 9.96 KiB | 231.00 KiB/s, done.
From standard_deviation
* branch HEAD -> FETCH_HEAD
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: refusing to merge unrelated histories
Edit 2
I am trying the git filter-repo
package and trying to follow the commands but there are some details I do not understand. Therefore I anoted it to see if I understood it correctly
cd /path/to/subdir1 # now at level of subdir1
cd .. # now at level of maindir
mv subdir1 maindir # while at level of maindir, now renaming subdir1 to maindir, so there is maindir containing another maindir
git filter-repo --to-subdirectory-filter subdir1/ # using the package
cd ../subdir2 # This is what I do not understand: why the `..`? because we should still be at the level of the first maindir. What am I not getting right?
git filter-repo --to-subdirectory-filter subdir2/ # did not try from this point on
cd ../maindir # did not try
git remote add -f s2 ../subdir2 # did not try
git merge --allow-unrelated-histories s2/main # did not try
git remote remove s2 # did not try