Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an automatic way to deduplicate .gitignore rules?

Is there some tool or webservice that takes a .gitignore file, tests the rules somehow and notifies one about duplicate rules (i.e. whose matches overlap)?

I have a long-running Git-repository that was initialised with several of GitHub's default .gitignore templates, which were amended manually over the course of several months. After removing some obvious duplicate ignore rules such as test-A.md and test-* manually I started wondering.

So far, I found methods to clean a text of duplicate phrases, but nothing that could actively evaluate the ignore rules. An answer may be useful for Syncthing and BitTorrent Sync users trying to clean up convoluted .syncignore rules. Thank you!

like image 808
Katrin Leinweber Avatar asked Oct 30 '22 20:10

Katrin Leinweber


1 Answers

There is no automatic tool available as per my knowledge. But you can make use of the git-check-ignore for each rule through the command line.

Example:

git check-ignore -v filename

From the documentation

For each pathname given via the command-line or from a file via --stdin, check whether the file is excluded by .gitignore (or other input files to the exclude mechanism) and output the path if it is excluded.

By default, tracked files are not shown at all since they are not subject to exclude rules; but see ‘--no-index’.

like image 52
Damodaran Avatar answered Nov 15 '22 05:11

Damodaran