我最好是用一个shell脚本替换符号链接的副本,还是有另一种方式告诉Git遵循符号链接?

PS:我知道这不是很安全,但我只是想在一些特定的情况下这样做。


当前回答

我使用的是Git 1.5.4.3,如果传递的符号链接后面有斜杠,它会跟着它。如。

# Adds the symlink itself
$ git add symlink

# Follows symlink and adds the denoted directory's contents
$ git add symlink/

其他回答

1. 您应该使用硬链接,因为在硬链接中所做的更改 由git上演。

2. 创建硬链接的语法为ln file1 file2。

3.这里file1是具有硬链接的文件的位置 您要创建的文件,而file2是硬链接的位置。

4. 我希望这对你有所帮助。

这是一个预提交钩子,它用这些符号链接的内容替换索引中的符号链接blobs。

把它放在.git/hooks/pre-commit中,并使其可执行:

#!/bin/sh
# (replace "find ." with "find ./<path>" below, to work with only specific paths)

# (these lines are really all one line, on multiple lines for clarity)
# ...find symlinks which do not dereference to directories...
find . -type l -exec test '!' -d {} ';' -print -exec sh -c \
# ...remove the symlink blob, and add the content diff, to the index/cache
    'git rm --cached "$1"; diff -au /dev/null "$1" | git apply --cached -p1 -' \
# ...and call out to "sh".
    "process_links_to_nondir" {} ';'

# the end

笔记

我们尽可能多地使用POSIX兼容功能;然而,diff -a不符合POSIX,可能还有其他原因。

这段代码中可能有一些错误/错误,即使它经过了一些测试。

我以前在符号链接之外添加文件已经有一段时间了。这在过去工作得很好,不需要做任何特别的安排。自从我更新到Git 1.6.1后,这就不再有效了。

您可以切换到Git 1.6.0来实现这个功能。我希望Git的未来版本会有一个Git -add标志,允许它再次跟随符号链接。

我使用的是Git 1.5.4.3,如果传递的符号链接后面有斜杠,它会跟着它。如。

# Adds the symlink itself
$ git add symlink

# Follows symlink and adds the denoted directory's contents
$ git add symlink/

符号链接的转换可能很有用。链接到Git文件夹中,而不是脚本中的符号链接。