I have a long (~2 years) repo with a lots of commits/branches, now for some reasons I need to change the root folder of the repository to one folder above.
Some examples to clarify the concept.
I have my repository inside a folder:
c:\workspace\test\src\
so in my repo has all the changes in files/subfolder of the above one.
I would like to move the repository to:
c:\workspace\test
being able from now on to add all the changes in the test folder mantaining the old repository history..
so all the old commits that are marked in folder "\"
, now should be checked in folder "\src"
for the old commits I can or can not have (it really does not matter) the actual content of the folder..
is that possible?
I hope what I explained is comprehensible..
I think you mean that the top-level directory of your repo is c:\workspace\test\
and you want c:\workspace\test\src\
to be the new top-level directory. First, check that this is the case:
cd c:\workspace\test\src
git rev-parse --show-toplevel #print repo top-level directory
It should print something like c:\workspace\test\
if that is really your top-level directory.
If it is, you can use the git filter-branch
rebasing command to make the 'src' directory the new top-level. Please be careful that this is what you really want to do as it will destructively modify your old history! Any commits affecting this branch will be rebased to contain the src
folder as the new top-level. Back up your current branch first.
cd c:\workspace\test\
git branch oldRoot #this backs up your current branch to a new branch called "oldRoot"
git filter-branch --subdirectory-filter src HEAD #this modifies your history
Warning!!! Note that:
For more info, read the "Making a Subdirectory the New Root" and "The Perils of Rebasing" sections in the Git Book.
If 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