我最好是用一个shell脚本替换符号链接的副本,还是有另一种方式告诉Git遵循符号链接?
PS:我知道这不是很安全,但我只是想在一些特定的情况下这样做。
我最好是用一个shell脚本替换符号链接的副本,还是有另一种方式告诉Git遵循符号链接?
PS:我知道这不是很安全,但我只是想在一些特定的情况下这样做。
当前回答
在Git 2.3.2+(2015年第一季度)中,还有一种情况下Git将不再遵循符号链接:参见由Junio C Hamano (gitster) (Git的主要维护者)提交e0d201b
适用:不要触及符号链接以外的文件
Because Git tracks symbolic links as symbolic links, a path that has a symbolic link in its leading part (e.g. path/to/dir/file, where path/to/dir is a symbolic link to somewhere else, be it inside or outside the working tree) can never appear in a patch that validly applies, unless the same patch first removes the symbolic link to allow a directory to be created there. Detect and reject such a patch. Similarly, when an input creates a symbolic link path/to/dir and then creates a file path/to/dir/file, we need to flag it as an error without actually creating path/to/dir symbolic link in the filesystem. Instead, for any patch in the input that leaves a path (i.e. a non deletion) in the result, we check all leading paths against the resulting tree that the patch would create by inspecting all the patches in the input and then the target of patch application (either the index or the working tree). This way, we: catch a mischief or a mistake to add a symbolic link path/to/dir and a file path/to/dir/file at the same time, while allowing a valid patch that removes a symbolic link path/to/dir and then adds a file path/to/dir/file.
这意味着,在这种情况下,错误消息不会是像“%s: patch不适用”这样的通用错误,而是更具体的错误:
affected file '%s' is beyond a symbolic link
其他回答
使用硬链接代替。这不同于软(符号)链接。包括git在内的所有程序都将该文件视为常规文件。注意,可以通过更改源或目标来修改内容。
macOS版本(10.13 High Sierra之前版本)
如果你已经安装了git和Xcode,安装hardlink。这是一个创建硬链接的微观工具。
要创建硬链接,只需:
hln source destination
macOS High Sierra更新
苹果文件系统支持目录硬链接吗? 苹果文件系统不支持目录硬链接。在macOS上从HFS+转换为APFS卷格式时,所有目录硬链接都转换为符号链接或别名。 来自APFS FAQ上developer.apple.com
关注https://github.com/selkhateeb/hardlink/issues/31了解未来的替代方案。
在Linux和其他Unix版本上
ln命令可以创建硬链接:
ln source destination
在Windows (Vista, 7,8,…)
使用mklink在Windows上创建一个连接:
mklink /j "source" "destination"
注意:从Git 1.6.1开始,这个通知就已经过时了。Git过去是这样的,现在不再是这样了。
Git默认情况下尝试存储符号链接,而不是遵循它们(为了紧凑,这通常是人们想要的)。
但是,当符号链接是一个目录时,我意外地设法让它在符号链接之外添加文件。
例如:
/foo/
/foo/baz
/bar/foo --> /foo
/bar/foo/baz
通过做
git add /bar/foo/baz
当我尝试时,它似乎起作用了。然而,这种行为在当时是我不想要的,所以我不能给你更多的信息。
1. 您应该使用硬链接,因为在硬链接中所做的更改 由git上演。
2. 创建硬链接的语法为ln file1 file2。
3.这里file1是具有硬链接的文件的位置 您要创建的文件,而file2是硬链接的位置。
4. 我希望这对你有所帮助。
在macOS上(我有Mojave/ 10.14, git版本2.7.1),使用bindfs。
酿造安装bindfs
cd / path / to / git_controlled_dir
mkdir local_copy_dir
bindfs </full/path/ source_dir> </full/path/ local_dir >
其他评论暗示了这一点,但在其他答案中没有明确提供。希望这能为大家节省一些时间。
我以前在符号链接之外添加文件已经有一段时间了。这在过去工作得很好,不需要做任何特别的安排。自从我更新到Git 1.6.1后,这就不再有效了。
您可以切换到Git 1.6.0来实现这个功能。我希望Git的未来版本会有一个Git -add标志,允许它再次跟随符号链接。