让 git 跟随符号链接(再次)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1500772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting git to follow symlinks (again)
提问by Peter
Somebody already asked how you can get git to follow symlinks. There was an answer for a symlinked directory, but not for a symlinked file. It was also over a year ago.
有人已经问过如何让 git 跟随符号链接。有一个符号链接目录的答案,但没有一个符号链接文件。这也是一年多前的事了。
Question: how do you get git to follow a symlink and add the file it refers to?
问题:如何让 git 跟随符号链接并添加它所指的文件?
Here is the old question: How can I get git to follow symlinks?. There's also a question about what git typically does How does git handle symbolic links?. I'm after a way of changing this behaviour.
这是一个老问题:我怎样才能让 git 跟随符号链接?. 还有一个关于git通常做什么的问题git如何处理符号链接?. 我正在寻找一种改变这种行为的方法。
In case you care: I'm running git 1.5.4.3 on unix and git version 1.6.0 on mac.
如果您关心:我在 unix 上运行 git 1.5.4.3,在 mac 上运行 git 版本 1.6.0。
采纳答案by Cascabel
I'm pretty sure there's no way.
我很确定没有办法。
Additionally, it sounds like a kind of insecure, undefined behavior - what should it do when you move between versions of the file and it needs to write to it? In particular, if you check out a revision before it was added, do you really want it to remove the contents of a file outside the repository? What happens if you come back to present and recreate the file, or if the symlink itself is modified - should git also track the symlink itself?
此外,这听起来像是一种不安全的、未定义的行为 - 当您在文件的版本之间移动并且需要写入时它应该怎么做?特别是,如果您在添加修订之前签出修订,您真的希望它删除存储库外文件的内容吗?如果您返回并重新创建文件,或者如果符号链接本身被修改会发生什么 - git 是否也应该跟踪符号链接本身?
Things along these lines were said on the git mailing listlate last year in response to essentially the same question.
回答by Marios Zindilis
You can use hardlinks instead of softlinks (a.k.a. symlinks). Git will then see the contents of the linked file. The disadvantage is that when someone checks out, the file is created as a normal file in the checked-out directory, because Git does not understand it as a link.
您可以使用硬链接而不是软链接(又名符号链接)。Git 然后会看到链接文件的内容。缺点是当有人签出时,该文件在签出目录中创建为普通文件,因为Git不会将其理解为链接。
回答by edmondscommerce
how about using hard links, then git has no idea its a linked file (does it?)
使用硬链接怎么样,那么 git 不知道它是一个链接文件(是吗?)
回答by a8ksh4
The trouble with using hardlinks is that if something writing to the other location replaces the file, rather than just writing changes to it, then the destination file has a new inode on the filesystem and the hardlink no longer points to it, so the files are out of sync.
使用硬链接的问题在于,如果写入另一个位置的内容替换了文件,而不是仅仅写入更改,那么目标文件在文件系统上有一个新的 inode 并且硬链接不再指向它,因此文件是不同步。