I have two git repositories:
git_repo_A: https://github.com/gnychis/coexisyst
git_repo_B: https://github.com/gnychis/android-wireless-monitor
I want to move everything in git_repo_A in to a subdirectory in git_repo_B called: application. I want to preserve all commits and file history.
So, after the move, git_repo_A would look like this:
git_repo_A/application/git_repo_B
I found this website that described basically the exact operation that I wanted: http://www.nomachetejuggling.com/2011/09/12/moving-one-git-repo-into-another-as-subdirectory/
So I gave it a shot, but I don’t think it did what I wanted it to.
What looks like ended up happening is two .* files in the main directory got added to git_repo_A/ … and then everything I wanted to show up as git_repo_A/application ended up as a delete operation. Here are the relevant two operations which got moved in to git_repo_A:
https://github.com/gnychis/android-wireless-monitor/commit/23e6639221733158d197bf7c29df8998e8a5c2ef
https://github.com/gnychis/android-wireless-monitor/commit/455ba86a80d8300b16bdd9527c444ebad78f7a9a
I followed the instructions exactly, but that doesn’t mean the instructions were correct. I think it is odd they moved the entire directory without re-adding it. However, I fear if you move it and then re-add it, it doesn’t preserve the file history.
I am the only person who uses these repositories. So it would also be good to hard reset everything that occurred on March 9 and start over: https://github.com/gnychis/android-wireless-monitor/commits/
I’ve done something very similar to this before. It’s almost identical to the process listed in your link, except this allows you to clean things up before committing your merge.
1) In RepoB (the one you want to keep) add a remote to RepoA
git remote add RepoA <path_to_repo>2) Fetch RepoA history into RepoB
git fetch RepoA3) Merge your relevant branches (assuming you’re on RepoB/master)
git merge RepoA/master4) Move the RepoA files to the appropriate subfolder and commit
git add .git commit -aIf you haven’t done anything to your RepoB since following the instructions you posted you can do this:
git reset HEAD~Now move any files and clean up what you need.
git add .git commit -aAs far as moving files and keeping history is concerned, git will track renames for a small number of files by default, since doing so is slow. If you want it to track everything you can use the following command
git config --global diff.renamelimit 0