Git 在项目文件夹外添加库?
Git add library outside of project folder?
我有以下项目结构:
我的程序/
.git/
我的程序/
File.c
File.h
主要File.c
MyProgram.exe
我的静态库/
我的静态库/
重要File.c
重要File.h
在 Microsoft Visual Studio 2015 中,我将 MyProgram 与 MyStaticLibrary 链接在一起,所以我可以在我的多个项目中使用 ImportantFile.c/h。但是,当要将其提交给 GitHub 时,我发现我找不到将 add
MyStaticLibrary
提交到存储库的方法。如果我尝试这样做,它会出现以下错误:
fatal ../MyStaticLibrary is outside repository
我不想进行任何合并或手动复制粘贴,因为如果我有 100 个库怎么办?那么你不能只在每次提交时复制粘贴。另一种选择是我不在我的存储库中包含 MyStaticLibrary
,但是任何希望编译我的代码的人都不能这样做。
我该怎么办?
可能是最简单的事情,除非您已经创建了一些要保存的历史记录,否则只需删除 .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.
同样,避免让项目需要存储库中没有或现成可用的东西。
我有以下项目结构:
我的程序/
.git/
我的程序/
File.c
File.h
主要File.c
MyProgram.exe
我的静态库/
我的静态库/
重要File.c
重要File.h
在 Microsoft Visual Studio 2015 中,我将 MyProgram 与 MyStaticLibrary 链接在一起,所以我可以在我的多个项目中使用 ImportantFile.c/h。但是,当要将其提交给 GitHub 时,我发现我找不到将
add
MyStaticLibrary
提交到存储库的方法。如果我尝试这样做,它会出现以下错误:fatal ../MyStaticLibrary is outside repository
我不想进行任何合并或手动复制粘贴,因为如果我有 100 个库怎么办?那么你不能只在每次提交时复制粘贴。另一种选择是我不在我的存储库中包含
MyStaticLibrary
,但是任何希望编译我的代码的人都不能这样做。我该怎么办?
可能是最简单的事情,除非您已经创建了一些要保存的历史记录,否则只需删除 .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.
同样,避免让项目需要存储库中没有或现成可用的东西。