简体   繁体   English

如何让 Windows 上的 Git 忽略符号链接

[英]How to get Git on Windows to ignore symbolic links

I can't get this to work.我无法让它工作。

I have cloned a repository that has a dummy file (named src): /path/src .我克隆了一个包含虚拟文件(名为 src)的存储库: /path/src

On Windows I have created a symbolic link: mklink -d /path/src /otherplace/src (but I of course had to delete the dummy src file first).在 Windows 上,我创建了一个符号链接: mklink -d /path/src /otherplace/src (但我当然必须先删除虚拟 src 文件)。
In both my .gitignore and .git/info/exclude I have在我的.gitignore.git/info/exclude我有

/path/src/ 
/path/src 
path/src/
path/src

And I have tried我试过了

git ls-files -s | gawk '/120000/{print $4}'

git update-index path/src/ --assume-unchanged

but I still get:但我仍然得到:

error: readlink("path/src"): Function not implemented
error: unable to index file path/src   
fatal: updating files failed

I have tried all these other suggestions .我已经尝试了所有这些其他建议 And even this doesn't work .即使这样也行不通
Any ideas?有任何想法吗?

You can do a checkout ignoring this single file like this:您可以执行忽略此单个文件的结帐,如下所示:

git checkout HEAD . --no path/src

The .gitignore file only works for adding stuff to the index. .gitignore文件仅适用于向索引添加内容。 Even a modifications on files commited before adding it to the .gitignore are not ignored.即使在将文件添加到.gitignore之前提交的文件修改也不会被忽略。

I know this is late, but I ran into this issue.我知道这已经晚了,但我遇到了这个问题。

In my case, I apparently had checked in my symlink at some point.就我而言,我显然已经在某个时候检查了我的符号链接。 So no matter what I did, .gitignore would not work (I think that is what Alexandre was getting at).所以无论我做什么, .gitignore都不起作用(我认为这就是 Alexandre 的意思)。

REPAIR:修理:

  1. Remove all symlinks删除所有符号链接
  2. See if git now thinks there are deleted files to commit.看看 git 现在是否认为有要提交的已删除文件。
  3. If so, then go ahead and commit the deletions.如果是这样,那么继续并提交删除。

Now you can re-add your symlinks and .gitignore should work.现在你可以重新添加你的符号链接, .gitignore应该可以工作了。

Here are my steps for this issue, similar, but a bit different from other answers.这是我针对此问题的步骤,类似但与其他答案有所不同。

Let's say I had a folder .fvm contain file.json and flutter_sdk(link) that all commited in git before, then I want to ignore out flutter_sdk .假设我有一个文件夹.fvm包含file.jsonflutter_sdk(link)之前都在 git 中提交,那么我想忽略掉flutter_sdk

  1. Add .fvm/flutter_sdk and .fvm/flutter_sdk/ in .gitignore ..gitignore中添加.fvm/flutter_sdk.fvm/flutter_sdk/
  2. Cut .fvm/flutter_sdk out to other place than the repository..fvm/flutter_sdk剪切到存储库以外的其他地方。
  3. git add. and git commit....git commit....
  4. Paste back the link.粘贴回链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM