Linking a single file from another git repository

人走茶凉 提交于 2019-11-29 00:56:41

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.

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.

In theory, "git: symlink/reference to a file in an external repository" suggests a solution combining submodule and symlink.
(from Pavel Šimerda)

$ 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), Gavriel reports in the comments that:

  • 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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!