I have my project in folder C:/projects/NameOfProject/MyCode/, and .git is located in folder MyCode/, so only MyCode's contents are in repository.
Recently I added some other files that are in the folder OtherFiles/ related to the project in folder NameOfProject/. I can't move these to MyCode/ due to relationship between files in MyCode/ and OtherFiles/. And now I need to change repository settings somehow, the folders MyCode/ and OtherFiles/ will be located at the root of repository. And moreover, it's highly desirable to continue commit history: next commit after changing root of repository will keep on the history of the current branch.
To summarize the above: I have repo in C:/projects/NameOfProject/MyCode/ and I want to move repo root to C:/projects/NameOfProject/ not moving files/subfolders in both of these folders.
How can I achieve that?
You need to rewrite directory names in the entire NameOfProject/MyCode/ repository using git filter-branch. I recommend to it this way:
MyCode to a temporary location.git filter-branch --tree-filter 'mkdir MyCode && mv * MyCode || :' -- --all. The filter will rewrite all branches; for every existing commit it creates a new subdirectory MyCode and moves all files into it (ignoring errors; there will be at least one error — cannot mv MyCode into MyCode). This is the main part of the entire process; it prepares the repository to expect all files in subdirectory MyCode instead of the root of the repository but preserves the commit history..git directory to C:/projects/NameOfProject/ (not to MyCode!) and cleanup temp dir.MyCode/.git.git add OtherFilesgit commit -m OtherFilesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With