简体   繁体   English

有没有一种方法可以将子模块添加到非空目录

[英]Is there a way to add a submodule to a non-empty directory

I am trying to add a common document (used by almost all of my products) to a folder that contains other documents necessary to my project. 我试图将一个通用文档(几乎所有我的产品都使用)添加到一个文件夹中,该文件夹包含我的项目所需的其他文档。 When I use git submodule add , I get the error that the directory is not empty, which is the point. 当我使用git子模块add时,出现错误,指出目录不为空。 If I add it any other way, it creates a new sub-directory which breaks all of my links to that file. 如果我以其他方式添加它,它将创建一个新的子目录,该子目录会断开我到该文件的所有链接。

a submodule lives in its own directory, mainly because git does not store the directory but a "file" pointing to the current head of the submodule. 子模块位于其自己的目录中,这主要是因为git并不存储目录,而是指向子模块当前头的“文件”。 This means that either you can add the file to the submodule, either you won't be able to use this directory for the submodule. 这意味着您可以将文件添加到子模块,或者您将无法将该目录用于子模块。

If I understood you correctly, your project X has a structure like: 如果我对您的理解正确,那么您的项目X的结构如下:

- /
  +- docs/
     +- projectdoc1.txt
     +- projectdoc2.txt

.. and then you have a common project in another git repository which contains (at least) a single document you want to integrate to project X? ..然后在另一个git存储库中有一个公共项目,该项目包含(至少)一个您要集成到项目X的文档?

(Also I'm assuming you have a bash shell for executing commands.) (我还假设您有一个用于执行命令的bash shell。)

Assuming this, you could perhaps use symlinks to resolve your issue? 假设这样,您也许可以使用符号链接来解决问题?

First, add the common project as a submodule in the root directory: 首先,将公共项目添加为根目录中的子模块:

git submodule add my-common-repo.git

Now you have 现在你有

- /
  +- docs/
  |  +- projectdoc1.txt
  |  +- projectdoc2.txt
  +- my-common-repo/
     +- commondoc.txt

Now, go to the docs subdirectory and create a link to the commondoc.txt: 现在,转到docs子目录并创建指向commondoc.txt的链接:

cd docs/
ln -s ../my-common-repo/commondoc.txt

Then you can add the link just like a normal file: 然后,您可以像添加普通文件一样添加链接:

git add commondoc.txt
git commit -m 'Add commondoc.txt symlink from my-common-repo'

That's it. 而已。 Now you have: 现在您有了:

- /
  +- docs/
  |  +- projectdoc1.txt
  |  +- projectdoc2.txt
  |  +- commondoc.txt
  +- my-common-repo/
     +- commondoc.txt

And whenever you update my-common-repo/ submodule, docs/commondoc.txt stays up-to-date. 并且每当您更新my-common-repo /子模块时,docs / commondoc.txt都会保持最新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM