2

I have a git repository which (for some reasons) contains some symbolic links (in unix-like operating systems). However, after I cloned it, each symbolic link is checked out as a regular text file containing the symbolic link destination. How should I let git checkout the links correctly?

A sample run of my command is attached below. In /tmp/a, path is a symbolic link to /some/path. However, in /tmp/b, the path is a regular file.

[user@host /tmp]$ mkdir a
[user@host /tmp]$ cd a
[user@host /tmp/a]$ git init
Initialized empty Git repository in /tmp/a/.git/
[user@host /tmp/a]$ ln -s /some/path
[user@host /tmp/a]$ git add path
[user@host /tmp/a]$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   path

[user@host /tmp/a]$ git commit -m 'add path'
[master (root-commit) 8e726b6] add path
 1 file changed, 1 insertion(+)
 create mode 120000 path
[user@host /tmp/a]$ ls -l
total 0
lrwxrwxrwx. 1 user group 10 Sep 17 14:35 path -> /some/path
[user@host /tmp/a]$ cd ..
[user@host /tmp]$ git clone file:///tmp/a/.git b
...
[user@host /tmp]$ cd b
[user@host /tmp/b]$ ls -l
total 4
-rw-rw-r--. 1 user group 10 Sep 17 14:36 path
[user@host /tmp/b]$ cat path
/some/path[user@host /tmp/b]$ 
[user@host /tmp/b]$ 
Eric Stdlib
  • 1,292
  • 1
  • 18
  • 32
  • 3
    Cannot reproduce; `b/path` is a symlink on my system (Mac). Check your [`core.symlinks`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-coresymlinks) setting (`git config --get core.symlinks`). For more details, see [How does Git handle symbolic links?](https://stackoverflow.com/questions/954560/how-does-git-handle-symbolic-links). – Amadan Sep 17 '19 at 06:58
  • Yes, the check solves my problem. I am using Fedora, and the default setting is `core.symlinks = false`. After I set it to `true`, git handles symbolic links as I expect. – Eric Stdlib Sep 17 '19 at 11:42
  • `core.symlinks` should be set correctly automatically depending on your system when a repository is initialized. What file system are you using in this case? – bk2204 Sep 17 '19 at 22:30
  • I am using ext4. – Eric Stdlib Sep 18 '19 at 23:34

0 Answers0