git - 如何将 Git 存储库放入另一个存储库中?

标签 git

所以我从存储库 A 克隆了这段代码,并在代码中创建了一个子文件夹 B。我所有的工作都是在子文件夹中完成的,我想将子文件夹置于版本控制之下,但我从来不想将 B 中的更改推送到存储库 A。事实上,我认为我什至没有对存储库 A 的推送访问权限。如何我可以将子文件夹 B 放入存储库 B 中吗?

我听说过子模块,但当我尝试使用它们时遇到错误:(我现在位于子文件夹 B 中)

user@host:~/code$ git init
Initialized empty Git repository in /pathtosubfolder/code/.git/

user@host:~/code$ git submodule add .
repo URL: '.' must be absolute or begin with ./|../
user@host:~/code$ git submodule add ./
fatal: could not create work tree dir ''.: No such file or directory
Clone of '/pathtosubfolder/code/' into submodule path '' failed
user@host:~/code$ git submodule status
user@host:~/code$ rm -rf .git
user@host:~/code$ git submodule init
You need to run this command from the toplevel of the working tree.

谢谢!

最佳答案

  1. 使用您的代码创建 B 存储库
  2. 在您的 A 项目文件夹中执行以下操作:

    git子模块添加git://repo-b-path.git代码

  3. 您必须在 A 存储库中使用“子模块”命令

关于git - 如何将 Git 存储库放入另一个存储库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20479175/

相关文章:

Gitlab:无法创建 ssh key

git - 如何缩小 .git 文件夹

git - C# 从 Azure 应用服务将文件推送到 Bitbucket 存储库?

node.js - 每次更改分支时如何避免 npm install?

xcode - 在大团队中使用 git VS Mercurial 和 Xcode 进行 iOS 开发有什么优缺点?

git - Visual Studio online 上的远程分支不会出现在 Visual Studio 2015 Team Explorer 上

git - 为什么 Heroku 中止 SSL 握手而不是 GitHub?

git - 在 git 中,您可以查看文件移动后应用于文件的旧提交吗?

git diff - 外部查看器 - 获取所有差异结果

Git:在 merge 提交上保留分支拓扑