Reputation: 501
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?
Upvotes: 4
Views: 2082
Reputation: 94406
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 OtherFiles
git commit -m OtherFiles
Upvotes: 6
Reputation: 539
You can initialize a new repo under C:/projects/NameOfProject/ by
git init
and pull the remote branch under that repo and just copy and replace those two folders MyCode and OtherFiles into initialized git repo and push it to your remote.
Upvotes: -1