Easier .gitignore file generation

You know when you start off building a kernel after creating a default .gitignore file containg list of object files and other temp files to be ignored, and at the end of a compilation, when you run a “git status”, you get a long list of new files that arent necessary to be included in the git. Manually adding them without wildcards is a headache. If you do add them with wildcards, you may potentially have conflicts with essential source scripts.

In this case, you can use the list output by git to your advantage.

You can just pipe the “git status” output to a file, and use it to add to your .gitignore.

Eg:

git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   .gitignore
#       modified:   include/config/kernel.release
#       modified:   include/generated/compile.h
#       modified:   include/generated/utsrelease.h
#       modified:   scripts/basic/fixdep
#       modified:   scripts/conmakehash
#       modified:   scripts/kallsyms
#       modified:   scripts/kconfig/conf
#       modified:   scripts/mod/elfconfig.h
#       modified:   scripts/mod/mk_elfconfig
#       modified:   scripts/mod/modpost
#       modified:   scripts/recordmcount
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       ..tmp_vmlinux1.cmd
#       ..tmp_vmlinux2.cmd
#       .missing-syscalls.d
#       .tmp_System.map
#       .tmp_kallsyms1.S
#       .tmp_kallsyms2.S
#       .tmp_versions/
#       .tmp_vmlinux1
#       .tmp_vmlinux2
#       .vmlinux.cmd
#       System.map
#       arch/arm/boot/.Image.cmd
#       arch/arm/boot/.zImage.cmd
#       arch/arm/boot/compressed/.piggy.lzma.cmd
#       arch/arm/boot/compressed/.vmlinux.cmd
#       arch/arm/boot/compressed/lib1funcs.S
#       arch/arm/boot/compressed/piggy.lzma
#       arch/arm/boot/compressed/vmlinux.lds
#       arch/arm/common/modules.builtin

Capture it to a file pipe.

git status > ../unnecessary.txt
cat ../unnecessary.txt | awk '{for(i=3;i<=NF;++i)print $i}'

 

 

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.