How does Git handle symbolic links?

后端 未结 3 632
鱼传尺愫
鱼传尺愫 2020-11-22 03:20

If I have a file or directory that is a symbolic link and I commit it to a Git repository, what happens to it?

I would assume that it leaves it as a symbolic link un

3条回答
  •  甜味超标
    2020-11-22 03:44

    Git just stores the contents of the link (i.e. the path of the file system object that it links to) in a 'blob' just like it would for a normal file. It then stores the name, mode and type (including the fact that it is a symlink) in the tree object that represents its containing directory.

    When you checkout a tree containing the link, it restores the object as a symlink regardless of whether the target file system object exists or not.

    If you delete the file that the symlink references it doesn't affect the Git-controlled symlink in any way. You will have a dangling reference. It is up to the user to either remove or change the link to point to something valid if needed.

提交回复
热议问题