In my Git repo, I have a directory A. In a branch, I've created a directory B under A. Is there a way to create/initialize a new Git repo in directory B? Would copying that directory, clearing all of the .git data, and do a git init in that new copied directory do the trick?
问题:
回答1:
Probably, but you'd lose all of your file history. This isn't a great approach. I'd think it's a better practice to clone the whole repo to a new folder, then discard the files you don't want using git rm.
回答2:
Note that you can split a git repo, making a subdirectory in its own repo with git filter-branch.
See "How can I split a repository apart into smaller atomic repositories?"
(and "Detach subdirectory into separate Git repository":
To rewrite the repository to look as if
foodir/had been its project root, and discard all other history:
git filter-branch --subdirectory-filter foodir -- --all That would allow you keep the history, but will rewrite the one of your original repo (meaning other contributors would have to reset their clone to your new history).
Once done, you can clone that new repo right where your subdirectory were: nested repos are ignored by the parent repo.
Or you can include that sub-repo as a submodule.