有没有办法将外部文件提交到当前存储库?

时间:2017-03-01 05:16:47

标签: git

我有一个Git存储库 d:\ repositories \ temp 和一个目录 d:\ temp1 ,我希望实现这一点:目录中的所有更改 d:\ temp1 并将其提交到存储库 d:\ repositories \ temp (本地和远程)。可能吗?感谢。

注意 :我在这里需要的功能可能类似于SVN的外部链接。

2 个答案:

答案 0 :(得分:4)

您可以将d:\temp1声明为:

  • 存储库本身(git init .)以记录其更改
  • d:\repositories\temp

    submodule
    git submodule add -b master -- /d/temp1
    git submodule update --init
    

请参阅“true nature of submodules”:

  • temp1将成为d:\repositories\temp
  • 的子文件夹
  • d:\temp1中所做的任何更改均可在d:\repositories\temp\temp1
  • git submodule update --remote内提交并更新

这样,temp在任何时候都会记录它正在使用的temp1的确切状态(我更喜欢to a subtree
正如我在“SVN:externals equivalent in GIT?”中提到的那样,即使它是not completely the same,也接近svn:external

请注意,如果您将temp推送到GitHub,您会看到temp1为灰色文件夹:该灰色文件夹为 gitlink (a {{ 3}})

如果使用--recursive选项克隆该GitHub存储库,您将获得temp1的内容,因为Git将能够克隆回/d/temp1
...
但是,没有其他人能够克隆您的GitHub repo 获取temp1内容,因为他们无法访问您的/d磁盘!

为了保留子模块的内容,最好先将temp1本身推送到自己的GitHub仓库,并temp通过其GitHub URL引用temp1(和不是通过本地路径/d/temp1special entry in the parent index更改子模块temp1的网址。

答案 1 :(得分:1)

Git有一个叫做子模块的功能,可以用来实现你想要实现的目标,下面看一下这个https://git-scm.com/book/en/v2/Git-Tools-Submodules

相关问题