从另一个 git 存储库链接单个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7597748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking a single file from another git repository
提问by Brendan Byrd
How do you link a single filefrom another git repository to your own repository? I don't want the full repository, just a single file. Using git submodule
seems like the right route to go, but it wants to grab the whole thing.
如何将另一个 git 存储库中的单个文件链接到您自己的存储库?我不想要完整的存储库,只想要一个文件。使用git submodule
似乎是正确的路线,但它想要抓住整个事情。
采纳答案by VonC
Considering that the unit of work for git is a repository (or more precisely a repository content), I don't think you can easily integrate one file.
考虑到 git 的工作单元是一个存储库(或者更准确地说是一个存储库内容),我认为您无法轻松集成一个文件。
If you don't need its history, you could consider simply copy it in your repo.
But if you do need the history, then some git filter-branch
(as in "git: How to split off library from project? filter-branch, subtree?") are in order. That seems a lot of effort for just one file though.
如果你不需要它的历史,你可以考虑简单地将它复制到你的仓库中。
但是如果你确实需要历史,那么一些git filter-branch
(如“ git:如何从项目中分离库?过滤分支,子树?”)是有序的。不过,对于一个文件来说,这似乎需要付出很多努力。
In theory, "git: symlink/reference to a file in an external repository" suggests a solution combining submodule and symlink.
(from Pavel ?imerda)
理论上,“ git: symlink/reference to a file in an external repository”提出了一个结合子模块和符号链接的解决方案。
(来自帕维尔·伊默达)
$ 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"
Since 2011 (original answer above), Gavrielreports in the commentsthat:
自 2011 年(以上原始答案)以来,Gavriel在评论中报告说:
- When I checkout the main repo, the linked file is not a symlink, but instead the file content is "
<reponame>/path/to/<linked_file>
". In other words git commits the symlink's target as file content- But the basic idea works.
I use "submodule/path/to/file
" instead of "file
" and it works
- 当我检出主存储库时,链接的文件不是符号链接,而是文件内容是“
<reponame>/path/to/<linked_file>
”。换句话说,git 将符号链接的目标提交为文件内容- 但基本的想法是可行的。
我使用“submodule/path/to/file
”而不是“file
”并且它有效