인디노트

Git 에 심볼릭 링크파일 사용하는 방법 본문

개발 플랫폼 및 언어

Git 에 심볼릭 링크파일 사용하는 방법

인디개발자 2017. 3. 18. 07:25
$ ln -s /Path/referenced/by/symlink symlink

Git doesn't know about this file yet. git ls-files lets you inspect your index (-s prints stat-like output):

$ git ls-files -s ./symlink
[Nothing!]

Now, add the contents of the symbolic link to the Git object store by adding it to the index. When you add a file to the index, Git stores its contents in the Git object store.

$ git add ./symlink

So, what was added?

$ git ls-files -s ./symlink
120000 1596f9db1b9610f238b78dd168ae33faa2dec15c 0       symlink

The hash is a reference to the packed object that was created in the Git object store. You can examine this object if you look in .git/objects/15/96f9db1b9610f238b78dd168ae33faa2dec15c.

The 120000 is the file mode. It would be something like 100644 for a regular file and is the mode special for links. From man git-config:

core.symlinks

If false, symbolic links are checked out as small plain files that contain the link text. git-update-index(1) and git-add(1) will not change the recorded type to regular file.

Use git cat-file -p to pretty-print the contents:

$ git cat-file -p 1596f9db1
/Path/referenced/by/symlink

So, that's what Git does to a symbolic link: when you git checkout the symbolic link, you either get a text file with a reference to a full filesystem path, or a symlink, depending on configuration. The data referenced by the symlink is not stored in the repository.

반응형
Comments