git 相当于 Subversion “开关”?
我有一些 SVN 存储库,我正在考虑切换到 git,但它们使用 Subversion“切换”功能的方式我不知道如何在 git 中模拟。我该怎么做?
举一个具体的例子:我将我的主目录保存在 SVN 中。我在我工作的许多计算机上检查过它。这对很多事情来说都很方便,但对少数人来说就不那么方便了。示例:
我有一个 www/ 目录,我在其中构建个人网站。我只在我的家用机器上工作这个网站,事实上,那里有一些文件,我不想散布到所有其他机器上。在存储库本身中,这是一个空目录,但是当我将存储库签出到我的家庭计算机时,我还将这个目录切换到存储库中的一个不相关的位置,即 www/ 实际上所在的位置。因此,大多数机器只会获得一个空的 www/,但选定的机器会获得内容。
我有一个 Documents/ 目录,其中包含 MacOS 文档。很多。它们在我的许多 Linux 机器上毫无用处。出于空间原因,我采用了上面提到的相同技巧:在存储库中,Documents 是空的,但在存储库路径的其他位置有一个实际的 Documents 文件夹,我在 Mac 上将 Documents/ 切换到该文件夹。
I have some SVN repositories I'm considering switching to git, but they use the Subversion "switch" function in ways I don't know how to emulate in git. How do I do this?
Taking one concrete example: I keep my home directory in SVN. I check it out to many computers where I work. This is very convenient for many things, but not so much for a few. Examples:
I have a www/ directory where I build a personal web site. I only work this site from my home machine, and in fact there are files there I don't want to splatter over all the other machines. In the repo itself, this is an empty directory, but when I check the repo out to my home machine, I also switch this directory to an unrelated location in the repo, where www/ actually lives. So most machines just get an empty www/, but selected machines get the contents.
I have a Documents/ directory, containing MacOS documents. Lots of them. They're useless on my many Linux machines. For space reasons, I pull the same trick mentioned above: in the repo, Documents is empty, but there's an actual Documents folder, elsewhere in the repo paths, to which I switch Documents/ on Macs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不是
switch
命令的初衷。无论如何,您正在考虑使用 git submodules 来实现您想要的功能。 www 和 Documents 可以是单独的 git 存储库,并且您可以将它们作为主 git 存储库中的子模块。这样,当任何人克隆存储库时,他们都会得到空文件夹,除非他们更新子模块。
如果您不需要子模块,则必须显式克隆 www 和 Documents 的单独存储库并将其放入您的存储库中。请注意,git 不会跟踪空文件夹,因此您将无法为这些文件夹添加占位符。
如果您不想要外部存储库,另一种方法(不是真正推荐)是使用 www:
PS: 真正的 git 等效于 svn switch 来创建孤立分支,因为它的用途是:
That is not what the
switch
command is meant for in the first place.Anyway, you are looking at using
git submodules
for what you want. The www and Documents can be seaprate git repositories and you have them as submodules in your main git repository. That way, when anyone clones the repo, they will get empty folders, unless they update the submodules.If you don't want submodules, you have to explicitly clone separate repos for www and Documents and put in your repo. Note that git doesn't track empty folders so you will not be able to have placeholders for these.
Another way (not really recommended) if you don't want external repos is to create orphan branch with say www:
PS: The real git equivalent of svn switch, for what it is intended for is: