Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 671
Magnus Johansson Avatar asked Jul 30 '12 20:07

Magnus Johansson


People also ask

Does git ignore symbolic links?

Git does not follow symbolic links when accessing a . gitignore file in the working tree. This keeps behavior consistent when the file is accessed from the index or a tree versus from the filesystem.

Does Git support symlinks on Windows?

Although Git supports symlinks, I would strongly recommend against storing them as links in your repository, especially if you're also working with that code on Windows.

Do symbolic links work on Windows?

Symlinks, or symbolic links, are “virtual” files or folders which reference a physical file or folder located elsewhere, and are an important feature built in to many operating systems, including Linux and Windows. The Windows' NTFS file system has supported symlinks since Windows Vista.

Can Git handle symbolic links?

Git can track symlinks as well as any other text files. After all, as the documentation says, a symbolic link is nothing but a file with special mode containing the path to the referenced file.


2 Answers

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.

like image 115
Alexandre Marcondes Avatar answered Sep 20 '22 20:09

Alexandre Marcondes


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.

like image 33
BruceJo Avatar answered Sep 19 '22 20:09

BruceJo