Git 在项目文件夹外添加库?

Git add library outside of project folder?

我有以下项目结构:

可能是最简单的事情,除非您已经创建了一些要保存的历史记录,否则只需删除 .git 子目录并在正确的目录中重做初始化。

如果您有 git 历史,大概您也可以执行以下操作:

$ mv .git ../
$ cd ..
$ git add . --all 
$ git status // => you can see all the files recognized as renamed 100%
$ git commit -m "Moves repo to root directory." 

对该错误消息的直截了当的解释是正确的:您无法添加文件 "above" 存储库。

理想情况下,您将版本 MyStaticLibrary/ 与所有依赖它的项目分开,并使用依赖管理器或 Git submodule 将源代码引入依赖它的项目。如果你有 100 个库都依赖于这样一个子模块,你会想要编写一个脚本来更新它们。


I don't want to do any merging or manual copy pasting because what if I had 100 libraries? Then you can't just copy paste on every commit.

这种本能很好;对手册说不 copy/paste.

Another option is for me to just not include MyStaticLibrary on my repository but then anyone who wishes to compile my code cannot do so.

同样,避免让项目需要存储库中没有或现成可用的东西。