告诉git忽略符号链接 [英] Telling git to ignore symlinks

查看:588
本文介绍了告诉git忽略符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题出现在这里这里,但他们似乎不匹配我所寻找的。

我在StaticMatic中做了一个项目,这是一个Ruby静态站点生成器。基本上,它只是一个带有Haml模板,Sass和CoffeeScript的src /目录。 StaticMatic提供了一个开发服务器来将它们编译到一个静态站点中,以及一个生成命令,它可以在build /中生成静态站点。



我对StaticMatic的修改是允许添加src / _modules / foo /,它可能包含src / _modules / foo / bar.haml。在运行服务器或构建站点时,会在src / bar.haml中创建符号链接,该链接指向foo /中的文件。



到目前为止这么好。 (处理冲突等)

_modules /中独立目录背后的推理是,它们可以作为git子模块进行跟踪并由其他团队独立检出。实质上,这允许多个团队在不同的页面(实际上是JS应用程序)在一个静态站点上工作,而不需要重复主布局等。

顺便说一下,git希望将这些符号链接视为文件。例如, git status 显示:

 #分支master 
#未追踪的文件:
#(使用git add< file> ...包含在将要提交的内容中)

#src / _modules / bar / foo。 haml
#src / foo.haml

...当我真的想要它时显示 src / _modules / bar / foo.haml 并忽略 src / foo.haml



一种方法是让我的链接生成代码将链接附加到.gitignore,但以编程方式混淆.gitignore会导致我容易出错。 (或许这种担忧是不合理的?)



我的理想解决方案如下所示:

  [filetype = link] 

... in .gitignore。据我所知,这是不可能的,或者是这样吗?

>

  find。 -type l | sed -e s'/ ^ \.\ /// g'>> .gitignore 

为所有文件查找输出./前缀。除非你把它关掉,否则gitignore无法对它们采取行动。一旦你在开头修剪。,它就像一个魅力


This question has appeared in similar forms here and here, but they don't seem to match up with what I'm looking for.

I'm making a project in StaticMatic, a Ruby static site generator. Basically, it's just a src/ directory with Haml templates, Sass, and CoffeeScript. StaticMatic provides a development server to keep compiling these into a static site, as well as a build command that generates the static site in build/.

My modification to StaticMatic is to allow the addition of src/_modules/foo/, which might contain src/_modules/foo/bar.haml. When running the server or building the site, a symlink would be created at src/bar.haml which points to the file in foo/.

So far so good. (Conflicts are handled, etc.)

The reasoning behind separate directories in _modules/ is that they could be tracked as git submodules and checked out independently by other teams. Essentially, this allows multiple teams to work on different pages (actually JS apps) in one static site without duplicating the main layout and such.

The hitch is that git wants to think of these symlinks as files. For instance, git status shows:

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be commited)
#
#       src/_modules/bar/foo.haml
#       src/foo.haml

...when I really just want it to show src/_modules/bar/foo.haml and to ignore src/foo.haml

One approach would be to have my link-generating code append the links to .gitignore, but messing with .gitignore programmatically strikes me as prone to error. (Perhaps this concern isn't reasonable?)

My ideal fix would be something like:

[filetype = link]

...in .gitignore. As far as I know nothing like this is possible, or is it?

解决方案

This seems to be a better idea

find . -type l | sed -e s'/^\.\///g' >> .gitignore

Find outputs a "./" prefix for all files. Unless you trim it off, gitignore is unable to act on them . Once you trim the ".\" at the beginning , it works like a charm

这篇关于告诉git忽略符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆