我们的开发人员混合使用Windows和基于unix的操作系统。因此,在Unix机器上创建的符号链接成为Windows开发人员的一个问题。在Windows (MSysGit)中,符号链接被转换为一个文本文件,并带有它所指向的文件的路径。相反,我想将符号链接转换为实际的Windows符号链接。
我对此的(更新的)解决方案是:
编写一个检出后脚本,递归地查找“符号链接”文本文件。
将它们替换为Windows符号链接(使用mklink),具有与虚拟“symbolic link”相同的名称和扩展名
通过在文件.git/info/exclude中添加一个条目来忽略这些Windows符号链接
我还没有实现这个方法,但我相信这是解决这个问题的可靠方法。
如果有的话,你认为这种方法有什么缺点?
这个后签出脚本是可实现的吗?也就是说,我能递归地找到Git创建的虚拟“符号链接”文件吗?
简单的回答:如果您可以启用开发人员模式,它们现在得到了很好的支持。
来自Windows 10的Symlinks !:
Now in Windows 10 Creators Update, a user (with admin rights) can
first enable Developer Mode, and then any user on the machine can run
the mklink command without elevating a command-line console.
What drove this change? The availability and use of symlinks is a big
deal to modern developers:
Many popular development tools like git and package managers like npm
recognize and persist symlinks when creating repos or packages,
respectively. When those repos or packages are then restored
elsewhere, the symlinks are also restored, ensuring disk space (and
the user’s time) isn’t wasted.
“创建者更新”的所有其他公告很容易被忽略,但如果启用了开发人员模式,则可以在没有提升权限的情况下创建符号链接。您可能必须重新安装Git并确保启用了符号链接支持,因为默认情况下并没有启用符号链接支持。
对于那些在Windows Vista、Windows 7或更高版本上使用Cygwin的人来说,原生git命令可以创建“适当的”符号链接,这些符号链接可以被Windows应用程序(如Android Studio)识别。你只需要设置CYGWIN环境变量来包含winsymlinks:native或winsymlinks:nativestrict,就像这样:
export CYGWIN="$CYGWIN winsymlinks:native"
这样做的缺点(也是一个很重要的缺点)是Cygwin shell必须是“以管理员身份运行”,这样它才能拥有创建这些符号链接所需的操作系统权限。但是,一旦创建了它们,就不需要特殊的权限来使用它们。只要它们没有在存储库中被另一个开发人员更改,git就可以在正常的用户权限下正常运行。
就我个人而言,我只对Windows应用程序(即非cygwin)导航的符号链接使用这种方法,因为这增加了难度。
有关此选项的更多信息,请参阅堆栈溢出问题:如何在Windows 7中使用Cygwin创建符号链接
简单的回答:如果您可以启用开发人员模式,它们现在得到了很好的支持。
来自Windows 10的Symlinks !:
Now in Windows 10 Creators Update, a user (with admin rights) can
first enable Developer Mode, and then any user on the machine can run
the mklink command without elevating a command-line console.
What drove this change? The availability and use of symlinks is a big
deal to modern developers:
Many popular development tools like git and package managers like npm
recognize and persist symlinks when creating repos or packages,
respectively. When those repos or packages are then restored
elsewhere, the symlinks are also restored, ensuring disk space (and
the user’s time) isn’t wasted.
“创建者更新”的所有其他公告很容易被忽略,但如果启用了开发人员模式,则可以在没有提升权限的情况下创建符号链接。您可能必须重新安装Git并确保启用了符号链接支持,因为默认情况下并没有启用符号链接支持。