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

标签 git

我有一个 Git 存储库 d:\repositories\temp 和一个目录 d:\temp1,我想实现以下目标:目录中的所有更改>d:\temp1 可以被检测到并提交到存储库d:\repositories\temp(本地和远程)。是否可以?谢谢。

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

最佳答案

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

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

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

参见“true nature of submodules”:

  • temp1 将成为 d:\repositories\temp 的子文件夹,
  • d:\temp1 中所做的任何更改都可以提交,并在 git 子模块更新后在 d:\repositories\temp\temp1 中更新 --远程

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

请注意,如果您将 temp 推送到 GitHub,您将看到 temp1 作为灰色文件夹:该灰色文件夹是 gitlink (special entry in the parent index)

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

为了保留子模块的内容,最好先将 temp1 本身推送到自己的 GitHub 存储库,然后 temp 引用 temp1 通过其 GitHub url(而不是通过本地路径 /d/temp1)。
See here更改子模块 temp1 的 url。

关于git - 有没有办法将外部文件提交到当前存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42523750/

相关文章:

Git 子模块与 Nuget 包

git - 如何将 gdoc 的修订历史导出到 git?

git - 我应该 git clone 我的依赖项吗?

git - 我如何压缩所有提交历史并推送到另一个远程存储库?

git - .gitignore 规则之间有和没有尾部斜杠的区别,如/dir 和/dir/

php - 如何仅对分支中已更改的文件进行 lint 或静态分析?

git - 如何查看远程标签?

git - 如何查看本地 git repo 和远程 repo 是否是相同的提交?

混帐致命 : multiple stage entries for merged file

git - Cloud9 IDE git 设置