Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telling git to ignore symlinks

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?

like image 202
user225643 Avatar asked Dec 28 '11 01:12

user225643


People also ask

Does Git ignore symbolic links?

Git does not follow symbolic links when accessing a . gitignore file in the working tree. This keeps behavior consistent when the file is accessed from the index or a tree versus from the filesystem.

How do I ignore a .Git file?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

What is .Git ignore?

gitignore file is a text file that tells Git which files or folders to ignore in a project. A local . gitignore file is usually placed in the root directory of a project. You can also create a global . gitignore file and any entries in that file will be ignored in all of your Git repositories.

What should I ignore in Git?

gitignore should list the names or name-patterns of files that will be found in work-trees when working with your project, but that should not be committed to the project. In other words, it's not OS-specific, it's project-specific.


2 Answers

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

like image 134
Biswajit_86 Avatar answered Oct 05 '22 23:10

Biswajit_86


Depending on what version of git you are using it should follow symlinks. There's a config setting core.symlinks, that may be set to false and thus not letting git follow them as directories (assuming git >= 1.6). It seems completely reasonable to have your symlinking script also append those links to the .gitignore file or just add them yourself. You could also do something like find . -type l >> .gitignore

like image 21
edwardsharp Avatar answered Oct 05 '22 22:10

edwardsharp