Moving a git repository down a hierarchy level

2020-06-14 04:23发布

问题:

I was searching for hours now but couldn't find a satisfying answere even though it appears to be simple noobish question. What I basically want to accomplish is to move my .git directory which currently resides besides my project folder down into the project folder. Optimally this shouldn't alter the repository history at all although I don't know whether this is actually possible. The reason I want to do this a somewhat IDE/project-type related problem I can solve this way.

I appreciate any help, thanks.

回答1:

Sure just move it, then do a

git add -A
git commit -m "moved project"

in the new root. It won't be a big change in terms of data. It's just going to change the current commit's tree. All objects already exist.



回答2:

If you want your git repository to be changed so that it always looked like your files were located in the new path, you could re-write history similar to this

Otherwise, Adam's answer is what you want.

EDIT: Note that you should NOT use this if you or anyone else may be already using this repository as a submodule or a subtree anywhere.