Use local .gitignore when one exists in the same directory#5207
Use local .gitignore when one exists in the same directory#5207dvic wants to merge 1 commit intojesseduffield:masterfrom
Conversation
When ignoring a file, check if a .gitignore already exists in the file's directory. If so, add just the basename to that local .gitignore instead of adding the full path to the root .gitignore.
|
This is an interesting improvement, but I don't think handling just this special case is good enough. There might also be a .gitignore file in one of the parent directories, so the least we should do is walk up the directory tree until we either find a .gitignore file, or hit the root. But then, users might still want to decide case by case which gitignore file they want to add it to, so presenting a menu with all the found alternatives would be best. Maybe we could also add them all to the main menu that appears after pressing What makes this a little complicated is that we want to improve the gitignore command in various ways, e.g. by also allowing to add glob patterns for the file extension instead of the file name verbatim, or allow users to edit the file. I don't have time to look up the issues or PRs where this was discussed. |
When ignoring a file with
i, if a.gitignorealready exists in the same directory as the file, the ignore rule is now added there (with just the basename) instead of the root.gitignore.This keeps ignore rules local to where a developer would naturally place them.
Falls back to root
.gitignorewith full path if no local one exists (existing behavior).