如何将 link 文件夹从 git 存储库转移到另一个存储库?
How to link folder from a git repo to another repo?
我想创建一个 public 存储库来放置我的主存储库(私有)中的一些示例文件。有什么方法可以将 link 几个文件夹从 git 存储库软化到另一个 git 存储库?
那么你应该为此任务使用子模块。
子模块是不同的 git 个相同根目录下的存储库。
这样您就可以在根存储库中的文件夹级别管理 2 个不同的项目
Submodules
allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.
git submodule
像目前一样将您的大项目分解为子项目。
现在使用 :
将每个子项目添加到您的主项目中
git submodule add <url>
将项目添加到您的存储库后,您必须对其进行初始化和更新。
git submodule init
git submodule update
自 Git 1.8.2 添加了新选项 --remote
git submodule update --remote --merge
会fetch
每个子模块中来自上游的最新变化, merge them in
和check out
子模块的最新版本。
正如the docs描述的那样:
--remote
This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch.
这相当于运行 git拉入每个子模块。
However, how would I push a commit in the scenario of bug fix in C which affects the code shared with the parent layers?
再次声明:使用子模块会将您的代码作为其内容的一部分放入主项目中。将其放在本地文件夹内或将其作为子模块的一部分之间的区别在于,在子模块中,内容被管理(提交)到不同的独立存储库。
这是子模块的图示 - 另一个项目中的项目,其中每个项目都是一个独立的项目。
git subtree
Git 子树允许您插入任何存储库作为另一个存储库的子目录
与 submodule
非常相似,但主要区别在于代码的管理位置。在子模块中,内容被放置在一个单独的 repo 中并在那里进行管理,这使您也可以将其克隆到许多其他 repo。
subtree
将内容作为根项目的一部分进行管理,而不是在单独的项目中。
与其写下如何设置它和了解如何使用它,您可以简单地阅读这个优秀的 post,它会解释这一切。
https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree/
回答你的 X 问题而不是你的 Y 问题 (xyproblem.info),你应该不使用子模块来完成这个任务。您应该创建一个 .gitignore 以从 VCS 中排除机密。或者,您可以让代码从 VCS 目录外部读取配置文件,这样您就可以将它们保存在 ~/.config 中。将配置文件存储在私有仓库中几乎从来都不是正确的方法。
P.S。 CodeWizard 的答案完美地回答了 Y 问题。
我想创建一个 public 存储库来放置我的主存储库(私有)中的一些示例文件。有什么方法可以将 link 几个文件夹从 git 存储库软化到另一个 git 存储库?
那么你应该为此任务使用子模块。
子模块是不同的 git 个相同根目录下的存储库。
这样您就可以在根存储库中的文件夹级别管理 2 个不同的项目
Submodules
allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.
git submodule
像目前一样将您的大项目分解为子项目。
现在使用 :
git submodule add <url>
将项目添加到您的存储库后,您必须对其进行初始化和更新。
git submodule init
git submodule update
自 Git 1.8.2 添加了新选项 --remote
git submodule update --remote --merge
会fetch
每个子模块中来自上游的最新变化, merge them in
和check out
子模块的最新版本。
正如the docs描述的那样:
--remote
This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch.
这相当于运行 git拉入每个子模块。
However, how would I push a commit in the scenario of bug fix in C which affects the code shared with the parent layers?
再次声明:使用子模块会将您的代码作为其内容的一部分放入主项目中。将其放在本地文件夹内或将其作为子模块的一部分之间的区别在于,在子模块中,内容被管理(提交)到不同的独立存储库。
这是子模块的图示 - 另一个项目中的项目,其中每个项目都是一个独立的项目。
git subtree
Git 子树允许您插入任何存储库作为另一个存储库的子目录
与 submodule
非常相似,但主要区别在于代码的管理位置。在子模块中,内容被放置在一个单独的 repo 中并在那里进行管理,这使您也可以将其克隆到许多其他 repo。
subtree
将内容作为根项目的一部分进行管理,而不是在单独的项目中。
与其写下如何设置它和了解如何使用它,您可以简单地阅读这个优秀的 post,它会解释这一切。
https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree/
回答你的 X 问题而不是你的 Y 问题 (xyproblem.info),你应该不使用子模块来完成这个任务。您应该创建一个 .gitignore 以从 VCS 中排除机密。或者,您可以让代码从 VCS 目录外部读取配置文件,这样您就可以将它们保存在 ~/.config 中。将配置文件存储在私有仓库中几乎从来都不是正确的方法。
P.S。 CodeWizard 的答案完美地回答了 Y 问题。