Telling git to ignore symlinks

后端 未结 8 1962
说谎
说谎 2020-12-08 06:13

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

相关标签:
8条回答
  • 2020-12-08 06:39

    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

    0 讨论(0)
  • 2020-12-08 06:41

    We had a similar issue where we needed to ignore a symlinked directory or a real directory, but not a subdirectory of the same name or a file starting with the same letters. For example:

    • Ignore - (symlink) ./media
    • Ignore - (directory) ./media
    • Do not ignore - ./something/media
    • Do not ignore - ./media.bak
    • Do not ignore - ./media-somethingelse

    I ended up using this in the .gitignore:

    media
    !*/media
    

    Which looks a little strange but is basically saying (line 1) ignore everything "media" but (line 2) do not ignore anything "media" that isn't in the root directory. This method does require a little specificity (in regards to not ignoring things in subdirectories) but should be pretty easy to adapt/extend.

    0 讨论(0)
  • 2020-12-08 06:44

    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

    0 讨论(0)
  • 2020-12-08 06:48

    My solution might seem silly, but I'd rather do this than update the .gitignore file every time a new file is added.

    I merely leave the links with a default name like "link to xxx" and then add the following line to my .gitignore file:

    link to *
    

    Then you just ensure you do not name any other files/folders with a name starting with "link to " and you're sorted.

    0 讨论(0)
  • 2020-12-08 06:49

    My answer from another question is relevant:

    for f in $(git status --porcelain | grep '^??' | sed 's/^?? //'); do
        test -L "$f" && echo $f >> .gitignore;
        test -d "$f" && echo $f\* >> .gitignore;
    done
    
    0 讨论(0)
  • 2020-12-08 06:52

    I used the most suitable solution to me - naming agreement.

    With files Each symlink to file in my solution had a prefix in a name like "bla.outsidemodule.ts". In .gitignore file, I had just:

    **/*.outsidemodule.*
    

    With folders Also on the root of the solution, I had folder "platform", which had common libs/modules for other parts of the solution. The structure was like it:

     - ./platform              <- sources
     - ./client/src/platform   <- symlink to ./platform
     - ./server/src/platform   <- symlink to ./platform
     - ./exchange/src/platform <- symlink to ./platform
     - ./service/src/platform  <- symlink to ./platform
    

    And in .gitignore just:

    **/platform <- exclude all "platform" folders
    !./platform <- do not exclude folder "platform" if it's on a root 
    
    0 讨论(0)
提交回复
热议问题