12

是否可以告诉 Git 忽略符号链接?我正在使用混合 Linux / Windows 环境,如您所知,符号链接在两者之间的处理方式非常不同。

4

2 回答 2

2

使用 git 版本 >= 1.6

Git 过去将符号链接视为与常规文件相同,但较新的 git 版本 (>= 1.6) 检查文件是否超出符号链接并会引发致命错误。

例如:

# git init 
# mkdir newdir 
# touch newdir/foo 
# git add newdir/foo 
# git commit -m 'add foo' 
# mv newdir /tmp/ 
# ln -s /tmp/newdir 
# touch newdir/bar 
# git add newdir/bar 
fatal: 'newdir/bar' is beyond a symbolic link

# git add/tmp/newdir
fatal: '/tmp/newdir' is outside repository

# git --version
git version 1.7.3.4
于 2011-04-19T12:22:00.663 回答
2

不,不可能在全球范围内这样做。但是,如果您有很多符号链接,这里有一个 bash 脚本,您可以使用它轻松地将它们添加到您的 repo 的 .gitignore 文件中:

for f in $(git status --porcelain | grep '^??' | sed 's/^?? //'); do
    test -L "$f" && echo $f >> .gitignore; # add symlinks
    test -d "$f" && echo $f\* >> .gitignore; # add new directories as well
done
于 2014-10-28T18:28:04.023 回答