gitignore binary files that have no extension

前端 未结 18 1121
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 02:14

How can binary files be ignored in git using the .gitignore file?

Example:

$ g++ hello.c -o hello

The

相关标签:
18条回答
  • 2020-11-28 02:18

    You may try in your .gitignore:

    *
    !*.c
    

    This approach has many disadvantages, but it's acceptable for small projects.

    0 讨论(0)
  • 2020-11-28 02:20

    I don't know any other solution but adding them one by one to .gitignore.

    A crude way to test is to grep the file command's output:

    find . \( ! -regex '.*/\..*' \) -type f | xargs -n 1 file | egrep "ASCII|text"
    

    EDIT

    Why don't you simply name you executable hello.bin?

    0 讨论(0)
  • 2020-11-28 02:21

    If you follow these commands on your .gitignore file and files still seems to appear you may want to try:

    git rm --cached FILENAME
    

    After that, add your .gitignore, commit and push. Took me 40 minutes to understand that, hope this helps to newbies like me

    0 讨论(0)
  • 2020-11-28 02:22

    Binary files are often without extensions. If this is your case try this:

    *
    !/**/
    !*.*
    

    REF: https://stackoverflow.com/a/19023985/1060487

    0 讨论(0)
  • 2020-11-28 02:24

    I created a .gitignore file with two entries in GOPATH directory.

    /bin
    /pkg
    

    It ignore all the compiled developments, currently.

    0 讨论(0)
  • 2020-11-28 02:27
    # Ignore all
    *
    
    # Unignore all with extensions
    !*.*
    
    # Unignore all dirs
    !*/
    
    ### Above combination will ignore all files without extension ###
    
    # Ignore files with extension `.class` & `.sm`
    *.class
    *.sm
    
    # Ignore `bin` dir
    bin/
    # or
    */bin/*
    
    # Unignore all `.jar` in `bin` dir
    !*/bin/*.jar
    
    # Ignore all `library.jar` in `bin` dir
    */bin/library.jar
    
    # Ignore a file with extension
    relative/path/to/dir/filename.extension
    
    # Ignore a file without extension
    relative/path/to/dir/anotherfile
    
    0 讨论(0)
提交回复
热议问题