问题
I am little bit confused as to when would you use .git/info/exclude
instead of ~/.gitignore (core.excludesFile)
to exclude files? I am clear when to use .gitignore
file present in project repository which is specific to that project, version-controlled and shared with other repo via clone but I am unable to understand difference between the above two somewhat user specific files to be ignored.
Thus, I am looking for difference between ~/.gitignore
and .git/info/exclude
and not between .gitignore (project dir)
and .git/info/exclude
.
UPDATE: I am unable to think specific usage of .git/info/exclude
as whatever files I want to ignore either fall in .gitignore
or ~/.gitignore
. It would really help if somebody can give an example for pattern/file that should specifically be included in .git/info/exclude
.
回答1:
Placing a file name or pattern in your global ignore file (~/.gitignore
or $XDG_CONFIG_HOME/git/ignore
) will suppress complaints about it in all repositories. Placing the same name or pattern in the per-repository ignore file (.git/info/exclude
) will suppress complaints only for that one repository.
Neither of these is inherently superior or inferior; they're just different. It's worth noting that ancient Git supported only the in-repository .gitignore
and .git/info/exclude
files, i.e., had no per-user, global ~/.gitignore
.
If you personally use an editor that makes backup files whose name ends with (say) $
instead of .bak
or .~
, and everyone else doesn't (and the everyone-else's backup files are already in a committed .gitignore
), you might put *$
in your personal ~/.gitignore
. If you only use this editor with this one project, it might make more sense to put this in .git/info/exclude
.
If the project itself makes a lot of to-be-ignored files, it makes sense to put these names into .gitignore
files that are committed into the project, but if there is some reason that this cannot be done, it then makes sense to put these patterns into .git/info/exclude
: they should not be ignored in other projects.
回答2:
From the docs,
Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow) should go into the $GIT_DIR/info/exclude file.
Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig.
If you are working on an IDE, it usually has IDE specific files such as project settings, workspace settings etc. These files are user and repository (different IDE for different projects...) specific. Such files can be excluded using $GIT_DIR/info/exclude
file.
With respect to this ~/.gitconfig
, the editor might leave some backup or temporary files such as nano keeping swap files in the directory during editing , so such files should be ignored globally for all repositories in the local system.
Still the question remains; is it safe to assume that .gitignore and ~/.gitignore is sufficient to specify what should be ignored?
.gitignore
should not be a problem since it is repository specific, however ~/.gitignore
might be a problem, consider a situation where a file is globally ignored using ~/.gitingore
for all the local repositories, and it turns out that the file was a necessary component for another repository, in that case $GIT_DIR/info/exclude
should be used.
来源:https://stackoverflow.com/questions/59673991/when-would-you-use-git-info-exclude-instead-of-gitignore-core-excludesfile