How can I configure git to ignore files?

There are some files that we want to ignore rather than track using git, and itโ€™s hard for us to figure out how to do this.

We have a third-party C library, which is unpacked, and we have it in Git. But when you configure && make , it creates many new files. How to write .gitignore to track source files, not new material. (this is not like banning *.o )

Edit : There are at least 12 file types. Therefore, we would like to NOT list which type we want and which we donโ€™t.

+4
source share
4 answers

Use ! to include all file types that you need. Something like the following example "

 * !*.c !*.h 
+6
source

Explicitly indicating which files should be monitored and ignoring all others may be the solution. * says to ignore everything, and the following lines identify files and directories that should not be ignored. Wildcards are allowed.

 * !filename !*.extension !directory/ !/file_in_root_directory !/directory_in_root_directory 

Remember that order matters. Putting * at the end makes all previous lines ineffective.

Take a look at man gitignore (5) and find ! . It says:

Templates have the following format:

  • (...)

  • Extra prefix! what denies the pattern; any comparable file excluded by the previous template will be included again. If it matches a negative template, this will override the source of the templates with a lower priority.

+3
source

I'm not sure why you say "this does not like the *.o ban", but I think you mean that there are no good templates that you can define that relate to the generated files, but not to the source files? If these are just a few things that appear (for example, separate embedded executables that often do not have a Linux extension), you can explicitly specify them in .gitignore , so they are not a problem.

If there really are many, many files that are generated by the build process that share extensions and other templates with source files, then just use templates that include your source files. You can even put * in .gitignore if it is really that bad. This means that when you enter git status no new files appear or are added when using git add . , but it does not harm any files that are already added to the repository; git will still tell you about the changes in them, and pick them up when you use git add . . It just loads you a bit to explicitly start tracking files that concern you.

0
source

I would make sure the repo is clean (no changes, no files without a trace), run configure && make , and then put the newly unprocessed entry in the ignore file. Something like git status --porcelain | fgrep '??' | cut -c4- git status --porcelain | fgrep '??' | cut -c4- git status --porcelain | fgrep '??' | cut -c4- pull them out automatically, but it would be useful for a while for the eyes to make sure that this is correct ...

0
source

Source: https://habr.com/ru/post/1383282/


All Articles