git ignore filenames which contain

后端 未结 1 1293
耶瑟儿~
耶瑟儿~ 2021-01-08 00:48

I am trying to tell git to ignore files which have \"_autosave\" somewhere in the filename. An example of such a file is:

hats/TFCB_ATV_TOP_HAT/_autosave-TFCB_ATV_H

相关标签:
1条回答
  • 2021-01-08 01:25

    Add this line to your .gitignore

    *_autosave*
    

    According to git help gitignore

    patterns match relative to the location of the .gitignore file

    Patternz like *_autosave* match files or directories containing "_autosave" somewhere in the name.

    Two consecutive asterisks ("**") in patterns mathed against full pathname may have special meaning

    A leading "**" followed by a slash means match in all directories.

    But "**/" seams redundant in some enviroments.

    EDIT:

    My machine at work (using git 1.7.1) does not have support for dubbel asterisk, but with *_autosave* it excludes the files.

    here is a simple test scrtipt (for Linux)

    DIR="$(mktemp -d)"
    git init $DIR/project1
    cd $DIR/project1
    cat > .gitignore <<EOF
    **/*_autosave*
    *_autosave*
    EOF
    mkdir dir1
    touch README foo_autosave dir1/bar_autosave
    git status
    
    rm -rf $DIR/project1
    
    0 讨论(0)
提交回复
热议问题