学习

Git下Windows与Linux符号链接兼容

2017-03-21  本文已影响1363人  raaay0608

简介

git for windows增加了符号链接的支持,其大体实现方法为,使用Windows Vista起增加的NTFS符号链接功能,模拟Linux下的符号链接,在使用git管理文件的过程中,由git在不同情况下自动转换。

本文正文翻译自git for windows的wiki文章Symbolic Links

相关链接:
创建符号链接
替换进程级令牌,对应下文原文中的Access Token Change

正文:符号链接

短版本:在Windows下没有和POSIX symlink完全等价的机制,而最为接近的解决办法,在Windows默认的非管理员用户下,是不可使用的。因此,symlink模拟支持默认是关闭的,需要用户手动配置。用户可以通过 core.symlinks=true来配置设置。

背景

从Windows Vista开始,Windows包含了对符号链接的支持。但这不是Unix的符号链接;它们在以下方面有所不同:

由于这些原因,Git for Windows默认禁用了对符号链接的支持(但遇到符号链接时Git仍能够读取)。你可以通过core.symlink配置变量来开启对符号链接的支持,例如,当克隆仓库时:

git clone -c core.symlinks=true <URL>

创建符号链接

默认情况下,Git Bash中的ln -s命令并非创建符号链接,而是创建复制。
若需要创建符号链接(需保证你的账户有相应的权限),使用mklink.exe,例如:

mklink /d this-link-points-to c:\that-directory
mklink this-link-points-to c:\that-file

允许非管理员用户创建符号链接

运行gpedit.msc(组策略编辑器),并增加账号到:计算机配置\Windows设置\安全设置\本地策略\用户策略\用户权限分配\创建符号链接

原文:Symbolic Links

thing is unavailable for non-admins by default. Therefore, symlink emulation support is switched off by default and needs to be configured by you, the user, via the core.symlinks=true config setting.

Background

Starting with Windows Vista, there is support for symbolic links. These are not your grandfather's Unix symbolic links; They differ in quite a few ways:

For those reasons, Git for Windows disables support for symbolic links by default (it will still read them when it encounters them). You can enable support via the core.symlinks config variable, e.g. when cloning:

git clone -c core.symlinks=true <URL>

Creating symbolic links

By default, the ln -s command in Git Bash does not create symbolic links. Instead, it creates copies.

To create symbolic links (provided your account has permission to do so), use the mklink.exe tool, like so:

mklink /d this-link-points-to c:\that-directory
mklink this-link-points-to c:\that-file

Allowing non-administrators to create symbolic links

Launch gpedit.msc (i.e. the group policy editor) and add the account(s) to Computer configuration\Windows Setting\Security Settings\Local Policies\User Rights Assignment\Create symbolic links.

上一篇 下一篇

猜你喜欢

热点阅读