你如何链接一个单个文件从另一个 git 存储库到您自己的存储库?我不需要完整的存储库,只需要一个文件。使用git submodule
看似正确的路线,但它想要抓住整个事情。
考虑到 git 的工作单元是一个存储库(或者更准确地说是一个存储库)content),我不认为你可以轻松地集成一个文件。
如果您不需要它的历史记录,您可以考虑将其复制到您的存储库中。
但如果你确实需要历史,那么一些git filter-branch
(如“git:如何将库从项目中分离出来?过滤器分支,子树? https://stackoverflow.com/questions/6403715/git-how-to-split-off-library-from-project-filter-branch-subtree") 是有序的。不过,对于一个文件来说,这似乎需要付出很大的努力。
理论上, ”git:对外部存储库中文件的符号链接/引用 https://stackoverflow.com/a/27770463/6309”建议结合子模块和符号链接的解决方案。
(from 帕维尔·西梅尔达 https://stackoverflow.com/users/2876370/pavel-%C5%A0imerda)
$ git submodule add /url/submodule/<reponame>
$ ln -s <reponame>/path/to/<linked_file>
$ git add .gitmodules <linked_file>
$ git commit -m "add a symbolic link to <linked_file> with the respective submodule"
自2011年以来(上面的原始答案),Gavriel https://stackoverflow.com/users/661589/gavriel报告在评论中 https://stackoverflow.com/questions/7597748/linking-a-single-file-from-another-git-repository/7597867#comment83181335_7597867 that:
- 当我签出主存储库时,链接的文件不是符号链接,而是文件内容是“
<reponame>/path/to/<linked_file>
”。
换句话说,git 将符号链接的目标提交为文件内容
- 但基本想法是有效的。
我用 ”submodule/path/to/file
“ 代替 ”file
”并且它有效
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)