[英]Ignore symbolic links in .gitignore
Is it possible to tell Git to ignore symlinks ? 有可能告诉Git忽略符号链接吗? I'm working with a mixed Linux / Windows environment and, as you know, symlinks are handled very differently between the two.
我正在使用混合的Linux / Windows环境,如你所知,符号链接在两者之间的处理方式截然不同。
No, it is not possible to do this globally. 不,全球无法做到这一点。 However, if you have lots of symlinks here is a bash script that you can use to easily add them to your repo's .gitignore file:
但是,如果你有很多符号链接,这里有一个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
Use git version >= 1.6 使用git version> = 1.6
Git used to treat sym-links the same as regular files, but newer git versions (>= 1.6) check if a file is beyond a symbolic link and will throw a fatal error. Git用于处理sym-links与常规文件相同,但较新的git版本(> = 1.6)检查文件是否超出符号链接并将引发致命错误。
eg: 例如:
# 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.