Hav*_*vok 38
你能忽略所有但源代码文件吗?
例如:
*
!*.c
!Makefile
Run Code Online (Sandbox Code Playgroud)
大多数开发人员通常build在他们的项目中有一个目录,其中运行实际的构建过程.因此,所有的可执行文件,.o,.so,.a,等在那里,这个build目录加入到.gitignore.
我编写了一个脚本,以将ELF可执行文件自动添加到中.gitignore。
git-ignore-elf:
#!/bin/sh
set -eu
cd "$(git rev-parse --show-toplevel)"
file=.gitignore
new=$file.new.$$
(
if [ -e "$file" ]; then
cat "$file"
fi
find . -name .git -prune -o -type f ! -name '*.o' ! -name '*.so' \
-print0 | xargs -0 file | grep ': *ELF ' | sed 's/:.*//' |
sed 's,^./,,'
) | perl -ne 'print if !$already{$_}++' >"$new"
mv "$new" "$file"
Run Code Online (Sandbox Code Playgroud)
特征:
这个单脚本版本在这里:http : //sam.nipl.net/b/git-ignore-elf-1
这是一个更具模块化的版本,它依赖于同一位置的其他脚本(git-root,find-elf,uniqo):http ://sam.nipl.net/b/git-ignore-elf