How to get Git on Windows to ignore symbolic links
Asked Answered
I

3

16

I can't get this to work.

I have cloned a repository that has a dummy file (named 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).
In both my .gitignore and .git/info/exclude I have

/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?

Ithnan answered 30/7, 2012 at 20:13 Comment(4)
did you solve the problem?Fumed
@Jus12, honestly I don't remember if I ever solved it. It was some time ago, and I don't remember which project it was.Ithnan
I don't have the answer, but I know setting git config core.symlinks true instead of git config core.symlinks false got rid of the Function not implemented error for me. Consequently, the symlinks I created using mklink in Windows were pushed without error, but when cloning the project again, the symlinks become text files that says where the original files are located instead of working as a real symlink.Sible
git config core.symlinks true works for me!Beadruby
A
3

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. Even a modifications on files commited before adding it to the .gitignore are not ignored.

Airport answered 17/9, 2012 at 20:11 Comment(2)
There doesn't seem to be a command for "git checkout HEAD . --no" "error: Ambiguous option: no" (Git 1.9.4)Gallnut
Yes @Gallnut it happened just now when I tested it. Will look for another solution.Airport
H
3

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).

REPAIR:

  1. Remove all symlinks
  2. See if git now thinks there are deleted files to commit.
  3. If so, then go ahead and commit the deletions.

Now you can re-add your symlinks and .gitignore should work.

Hardenberg answered 21/3, 2020 at 23:30 Comment(1)
Thanks it was more simple and easy than other steps !Antevert
S
1

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.

  1. Add .fvm/flutter_sdk and .fvm/flutter_sdk/ in .gitignore.
  2. Cut .fvm/flutter_sdk out to other place than the repository.
  3. git add . and git commit ....
  4. Paste back the link.
Slapdash answered 21/12, 2020 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.