Ignore File: ability to specify which .gitignore file to use

Chris Jaquet 3 years ago updated by Thomas Singer 2 years ago 8

Having .gitignore files throughout a project's folders can make it difficult to manage the ignore rules for a particular project. It would be helpful when ignoring a file to be shown a dialogue which asks the user which .gitignore file to use - current folder (i.e. the folder containing the files to ignore) or repository root (the .gitignore in the root of the repository). An additional "nice to have" would be to be able to specify the default using a checkbox on the dialogue (as is done with the "Reset" dialogue in the log view.

Satisfaction mark by Chris Jaquet 2 years ago

Not sure about this one as it would conflict with behaviour specified in official git docs:

Each line in a gitignore file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):
  • Patterns read from the command line for those commands that support them.
  • Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

I do not see why there would be a conflict. The format of the pattern would change depending on which .gitignore the user chooses to use, and yes, the order of precedence of the .gitignores should still prevail (as they must do in SmartGit anyway).

An example. I choose to ignore the file "doc\Doxyfiles\doxyfile.cmake":

  1. If I choose to ignore using the root gitignore the result in the .\.gitignore is: "/doc/Doxyfiles/doxyfile.cmake"
  2. If I choose to ignore in the current folder, the result in "doc\Doxyfiles\.gitignore" is simply "/doxyfile.cmake"

Naturally there are a number of other options that could also be provided to the user:

  • Ignore recursively in sub folders
  • Add the ignore to the ".git/info/exclude" file, etc

However, I am most interested in the two choices I have indicated. Currently to ignore a file using only the root .gitignore requires me to leave SmartGit and either edit the file manually (which is quite tedious if you have many files in many (sub) folders) or use an external tool (such as TortoiseGit, which while less tedious will not allow the selection of many items in the "flat" view presented by SmartGit.)

This would be hard to implement because one can select files from different repositories. The light-weight variant https://smartgit.userecho.com/communities/1/topics/301- is implemented now.

It would be handy to be able to do this even if only one repo could be selected at a time. When I said "Flat" view, what I mean is that when a (single) repo is selected, Smartgit can be configured to show all files in a flat structure, independent of sub-directories (within the repo). This is my normal way of working with a single repo. It agree it would be challenging to try implement this when multiple repos are selected/open/viewed at the same time, but I would be happy with the ignore option defaulting to current (or light-weight) behaviour for the multiple repo case.

Coming from Sourcetree, I really found SmartGit's approach dumbed down version of what Sourcetree was doing. Seriously: check that out, because it's quite good.

In most of the projects I've been working on, there is just single .gitignore in root of the project (these are usually Unity projects where the ignore is almost identical from project to project). I prefer to have single ignore file per project. I really don't want to sprinkle ignore files in random subdirectories.

Please checkout SmartGit 18.1.

Thanks for the implementation in SmartGit 18.1 The combo-box drop-down menu on the Ignore dialogue is precisely what I was looking for.


Perfect. I thought, the full version would include to allow creating/using a .gitignore file in every parent directory up to the root.