This is a trivial description that might miss important parts, but maybe it will lead you in the correct direction.
Create the new repo first (assuming the repositories are at the same place in the directory structure)
mkdir -P NewRepo/NewProject
cd NewRepo
git init
Then add your old repositories one at a time
git remote add repo1 ../Repo1
git fetch repo1 # This will add Repo1 including the git history to NewRepo
Then move your branch to the correct place in Repo1. Assuming you have a master branch on top in Repo1 you can
git reset --hard repo1/master
or
git checkout repo1/master
Now you can move your files to the correct directory. Add and commit.
mv Project1 NewProject
git add NewProject
git commit -m 'Moved Project1 to NewProject'
Then it is the same steps for Repo2.
Here you might want to remove the remote repositories.
git remote remove repo1
git remote remove repo2
The history should not be a big issue. gitk --all
will show you the history in a correct way. If you want to change the order you can always use git rebase -i
.
git rebase -i <oldest commit to handle>
This will start your favorite editor with all commits listed. Here you can rearrange the order of them. When you save and quit the editor git
will apply your changes from where you are. That is; the old history will remain.
If you really, really want to change history you also have the command git filter-branch
, but that tool is outside of my comfort zone.