0

We're in a situation where we want two different repos to be in one repo since they were split originally for various reasons that aren't applicable anymore, and because the history is so messy (and because we're solidifying a new git flow), we're considering keeping the old repos on our old host and the new repo with the combined folders on our new host.

I'd like to keep the history but also not have confusion over files in the new repo having a slightly different path (because a new top-level folder is being added) in a diff with the file changes when they had the old path (without their new top-level folder), and I'm not sure there's a way to do this, especially while not having a new commit which may cause all files to show as added/deleted (and thereby screwing up a diff between new/old repo history) just because the path is changing for all files.

Is this even feasible, or would it be better to just start anew? The original repos were only created years after the code was made because the development team was replaced and didn't use versioning or even much structure planning at all.

Hugo y
  • 1,421
  • 10
  • 20
Dave Heq
  • 356
  • 4
  • 18
  • 1
    This is totally feasible, but it's hard to give specifics without details. Look into [`git-filter-branch`](https://git-scm.com/docs/git-filter-branch) for how to move directories for all history. Alternatively, just move the files and Git will notice it's a rename, not an add/delete. – Schwern Jan 22 '16 at 01:26
  • Possible duplicate of [git move file and directory into a sub-directory along with commit history](http://stackoverflow.com/questions/18667308/git-move-file-and-directory-into-a-sub-directory-along-with-commit-history) – Schwern Jan 22 '16 at 01:28
  • @Schwern: I tried just moving the .git folder above the main folder (call it A), so that now git includes it's brother folder (call it B), and then modified the .gitignore, but it thinks that I deleted everything and added it all back to the main-now-subfolder as new files (new: & deleted: entries), and I don't know why it doesn't recognized they were just moved into a sub-folder. I'll research git-filter-branch, thanks. – Dave Heq Feb 17 '16 at 21:38
  • 1
    Moving the `.git` folder will only cause more problems, put it back. Look into the tools and answers I already mentioned. – Schwern Feb 17 '16 at 22:13
  • @Shwern: I have to move the .git folder because it's in the sub-folder of the new repository, or I have to delete it and create a new .git folder above the sub-folder. – Dave Heq Feb 17 '16 at 22:37
  • @Shwern as to your possible duplicate comment, I'm not moving any files, I just need the git repo to be in the parent folder of what it is; I have two repos, one is large (the main one, A), the other is small (B), and the repo needs to contain both folders, which are already side-by-side to each other. – Dave Heq Feb 17 '16 at 22:42
  • 1
    I'll say it again, ***moving the `.git` folder will only make the problem worse***. You are moving files, you just don't know it yet. :) Instead of moving the git repo, you'll move the directories inside of it. If you add a before and after illustration of the directory and repository structure I think I can walk you through it. – Schwern Feb 18 '16 at 00:09
  • @Schwern OK, so then I create a new folder (call it "C", which will be in folder "A" where the .git folder is), move all the other folders and files in folder "A" (besides the .git folder and .gitignore) into folder "C", then move the "B" folder (above the .git folder) in there, then delete the .git folder and .gitignore file inside folder "B", then modify the .gitignore file in folder "A"? That mucks up server routing and is effectively the same thing as moving the .git folder up one folder because git works relative to the .git folder not absolute to the filesystem. – Dave Heq Feb 19 '16 at 16:19
  • 1
    Until you show a before and after directory structure illustrating what you have and what you want I can't help you. – Schwern Feb 19 '16 at 18:33

0 Answers0