git commit symlink as a regular file

hasen picture hasen · Dec 12, 2011 · Viewed 14.9k times · Source

Suppose I have a file fname which is a symlink to a file from some other repository/project, say ../../proj2/fname.

Is there a way to add/commit fname as a regular file?

It seems that, by default, git gives the file mode 120000 and sets the path to the linked file as the blob content.

I know this because git ls-tree shows mode 120000 for the file, and git cat-file -p shows ../../proj2/fname as the blob's content.

Answer

mgarciaisaia picture mgarciaisaia · Mar 6, 2013

If you want the file to appear instead of the link, you should probably use the ln command to create a hard-link instead of a sym-link (ln -s).

Making a hard-link, you can make the same file to appear under two different directories, so changing it via any of the links will reflect changes via both links, and the file will live in both directories, so it will be tracked by git.

I hope Windows' mklink /j command in Bukov's answer does this, but I really don't know at all.