How to add symlink file to a gitlab repo

懵懂的女人 提交于 2019-12-22 18:35:26

问题


How can I add symlink to file to gitlab repository?

Every time I run a pipeline from gitlab, the local symlink gets destroyed.

Any suggestions on how to create a symlink for a folder which resides inside of gitlab repo would be great.


回答1:


To find out, first, make a symbolic link:

$ 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
$

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.




回答2:


You can store in a Git repo a symlink (special entry 12000), but, as seen in this test, that would make the GitLab pipeline fail.
See gitlab-ce issue 27542 (though it is for the particular case of .gitlab-ci.yml being a symlink).

It is best if the pipeline first recreate the symlink, then process in its subsequent steps, with the normal build: regenerating it seems better than storing it.



来源:https://stackoverflow.com/questions/46510179/how-to-add-symlink-file-to-a-gitlab-repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!