git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] user-manual: Add section on ignoring files

From
Junio C Hamano <junkio@cox.net>
Date
May 15, 2007, 23:30 UTC
Message-ID
<7v1whhis16.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200705160047.52717.johan@herland.net>
Johan Herland <johan@herland.net> writes:
> +[[ignoring-files]]
> +Ignoring files
> +--------------
Looks good ;-).
Show 6 quoted lines
> +A project will often generate files that you do 'not' want to track with git.
> +This typically includes files generated by a build process or temporary
> +backup files made by your editor. Of course, 'not' tracking files with git
> +is just a matter of 'not' calling "git add" on them. But it might be
> +annoying to have these untracked files automatically showing up in the
> +output of "git status", in the commit message template, etc.

Another point about this annoyance factor is that "git-add ." does not add files that are excluded.

Show 6 quoted lines
> +Git therefore provides "exclude patterns" for telling git which files to
> +actively ignore. Exclude patterns are thoroughly explained in the
> +"Exclude Patterns" section of the gitlink:git-ls-files[1] manual page,
> +but the heart of the concept is simply a list of files which git should
> +ignore. Entries in the list may contain globs to specify multiple files,
> +or may be prefixed by "`!`" to explicitly include (un-ignore) a file.

I think you can safely teach the reader that later entries override the earlier ones here, as you are about to give such an example just below.

Show 13 quoted lines
> +The following example should illustrate such patterns:
> +
> +-------------------------------------------------
> +# Lines starting with '#' are considered comments.
> +# Ignore foo.txt.
> +foo.txt
> +# Ignore (generated) html files,
> +*.html
> +# except foo.html which is maintained by hand.
> +!foo.html
> +# Ignore objects and archives.
> +*.[oa]
> +-------------------------------------------------
Show 12 quoted lines
> +The next question is where to put these exclude patterns so that git can
> +find them. Git looks for exclude patterns in the following files:
> +
> +`.gitignore` files in your working tree:::
> +	   You may store multiple `.gitignore` files at various locations in your
> +	   working tree. Each `.gitignore` file is applied to the directory where
> +	   it's located, including its subdirectories. Furthermore, the
> +	   `.gitignore` files can be tracked like any other files in your working
> +	   tree; just do a `git add .gitignore` and commit. `.gitignore` is
> +	   therefore the perfect place to put exclude patterns that match
> +	   ignored files that pop up in every copy of your project, such as
> +	   build output files (e.g. `\*.o`), etc.

... and more importantly, the patterns that are _meant_ to be shared by all the project participants. I think it is probably easier to follow if you explain that in-tree .gitignore is not about personal preference upfront in this section, rather than saying it in .git/info/exclude section.

Previous: Johan HerlandNext: Johan Herland
Message 4 of 9 in “user-manual: Add section on ignoring files”
  1. user-manual: Add section on ignoring filesJohan Herland, May 15, 2007
  2. Jakub NarebskiMay 15, 2007
  3. Johan HerlandMay 15, 2007
  4. Junio C HamanoMay 15, 2007
  5. user-manual: Add section on ignoring filesJohan Herland, May 16, 2007
  6. Junio C HamanoMay 16, 2007
  7. Johan HerlandMay 16, 2007
  8. J. Bruce FieldsMay 16, 2007
  9. Johan HerlandMay 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.