git - 将 git repo 的一部分作为子模块添加到另一部分

标签 git git-submodules mount

我需要将我的项目中的一个文件夹复制到另一个文件夹中。但是当我尝试时:

git 子模块添加 ./first-folder ./second-folder/sumbodule

它失败了:

fatal: clone of '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddbab4a99dbab4a9b5a8bff3beb2b0" rel="noreferrer noopener nofollow">[email protected]</a>:username/projectname.git/first-folder' into submodule path

我是否做错了什么,或者默认情况下这是不可能的,我应该以某种方式安装它?谢谢。

最佳答案

您只能将整个存储库添加为子模块。请参阅git submodule documentation 。有一个参数path,但它适用于子模块出现在“ super 项目”中的路径,而不是子模块内的路径。

要实现您想要的目标,您需要将 first-folder 设为单独的 git 存储库,并将其作为子模块包含到您的所有项目中。

关于git - 将 git repo 的一部分作为子模块添加到另一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55568771/

相关文章:

Git 不跟踪现有文件中的更改

gitlab - 致命: Needed a single revision(gitlab runner error)

git - 为什么git会说“未暂缓提交更改”并指示子模块文件夹?

c++ - 在 Linux 和 Mac 上处理可移动媒体 USB/CD-ROM 挂载/卸载事件

docker - 带有复制 Controller 的 Kubernetes 卷挂载

git - 推送后无法在 git 中压缩提交 - Visual Studio

git - 没有 git remove 删除文件。现在它在 repo 中,而不是本地的。如何从 repo 中删除?

git - git submodule update --recursive 是否会覆盖 fetchRecurseSubmodules?

java - 通过应用程序在 Android 设备中执行挂载命令

git - 检查推送的标签是否在 git Remote 上