我有一个 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/