gitignore binary files that have no extension

前端 未结 18 1254
没有蜡笔的小新
没有蜡笔的小新 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:32

    To append all executables to your .gitignore (which you probably mean by "binary file" judging from your question), you can use

    find . -executable -type f >>.gitignore
    

    If you don't care about ordering of lines in your .gitignore, you could also update your .gitignore with the following command which also removes duplicates and keeps alphabetic ordering intact.

    T=$(mktemp); (cat .gitignore; find . -executable -type f | sed -e 's%^\./%%') | sort | uniq >$T; mv $T .gitignore
    

    Note, that you cannot pipe output directly to .gitignore, because that would truncate the file before cat opens it for reading. Also, you might want to add \! -regex '.*/.*/.*' as an option to find if you do not want to include executable files in subdirectories.

提交回复
热议问题