如何管理git中重叠的存储库,包括同一目录中的文件? [英] How can I manage overlapping repositories in git, including files in the same directory?
问题描述
我有一个复杂的存储库,有时代码段之间的逻辑边界跨越目录边界.有时,目录X中的单个文件确实需要与目录Y中的文件一起使用.
I have a complex repository where sometimes the logical boundaries between code segments crosses directory boundaries. Sometimes a single file in directory X really needs to go with files in directory Y.
例如,假装我有一个中央仓库,看起来像这样:
E.g., pretend I have a central repo that looks like this:
a/foo
a/bar
b/baz1
b/baz2
...并且我希望我的本地存储库以a/*
和b/baz1
结尾,但不以b/baz2
结尾.其他文件应最终放在另一个存储库中.
...and I want my local repository to end up with a/*
and b/baz1
, but not b/baz2
. The other files should end up in another repository.
(是的,长期的解决方案是移动文件,但是在进行重构时,我需要适当地控制文件的版本.)
(Yes, the long term solution is to move the files, but while I am working on that refactoring, I need to version-control the files appropriately.)
我可以使用git来做到这一点吗?
Can I use git to do this?
推荐答案
您可以使用Git的此或参见man git-read-tree
).在克隆的存储库中运行以下命令:
You can do this with Git's sparse checkout feature (if that link still doesn't work, try this one or see man git-read-tree
). Run the following commands in your cloned repository:
git config core.sparsecheckout true
echo '*' >.git/info/sparse-checkout
echo '!b/baz2' >>.git/info/sparse-checkout
git read-tree --reset -u HEAD
这将从您的本地工作目录中删除现有的b/baz2
文件.它仍然在存储库中,但是您本地的Git不会在意它是否已经从工作目录中消失了.
This will delete the existing b/baz2
file from your local working directory. It's still in the repository, but your local Git will not care about the fact that it's gone from the working directory.
这篇关于如何管理git中重叠的存储库,包括同一目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!