diff mbox series

[v3,1/4] gitfaq: files in .gitignore are tracked

Message ID 20200421131223.29337-2-shouryashukla.oo@gmail.com (mailing list archive)
State New, archived
Headers show
Series gitfaq: add issues in the 'Common Issues' section | expand

Commit Message

Shourya Shukla April 21, 2020, 1:12 p.m. UTC
Add issue in 'Common Issues' section which addresses the problem of
Git tracking files/paths mentioned in '.gitignore'.

Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
---
 Documentation/gitfaq.txt | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Junio C Hamano April 21, 2020, 7:45 p.m. UTC | #1
Shourya Shukla <shouryashukla.oo@gmail.com> writes:

> Add issue in 'Common Issues' section which addresses the problem of
> Git tracking files/paths mentioned in '.gitignore'.

I do not think this much text is warranted in this file.

The first part of Documentation/gitignore.txt *ought* to cover this
material and it does say "specifies intentionally untracked files"
and "already tracked byt Git are not affected".  Read that paragarph
twice, and then jump to the NOTES section it refers two and also
read that twice.  Then let's work on polishing these places if there
is anything unclear.  I think what we have there is clear enough.

And then trim the text we see here down.  The way the question is
phrased may be good as-is (I trust that you researched to make sure
that is how the question is most frequently phrased).  The answer
should be just "see gitignore(5)", or perhaps repeat the first
paragraph of gitignore(5) and then refer to the page, i.e. no more
than

    [[files-in-.gitignore-are-tracked]]
    I asked Git to ignore various files, yet they are still tracked::
            A `gitignore` file specifies intentionally untracked files
            that Git should ignore.  Files already tracked by Git are
            not affected.  See linkgit:gitignore[5] for details.

should be in the FAQ file.
diff mbox series

Patch

diff --git a/Documentation/gitfaq.txt b/Documentation/gitfaq.txt
index 1cf83df118..96767e7c75 100644
--- a/Documentation/gitfaq.txt
+++ b/Documentation/gitfaq.txt
@@ -223,6 +223,27 @@  a file checked into the repository which is a template or set of defaults which
 can then be copied alongside and modified as appropriate.  This second, modified
 file is usually ignored to prevent accidentally committing it.
 
+[[files-in-.gitignore-are-tracked]]
+I asked Git to ignore various files, yet they are still tracked::
+	Git ignores files matching the patterns stated in the '.gitignore'.
+	Consequently, `git add` does not add the files/paths matching the
+	pattern in `.gitignore`, meaning they remain untracked; `git status`
+	does not list the aforementioned files/paths as untracked.
+
+	One thing to note is that the `.gitignore` mechanism applies only
+	to the files that are not already tracked. A file/path that is
+	already tracked will stay to be tracked even if you add a pattern
+	that happens to match it to `.gitignore` file.
+
+	This is probably the reason why Git shows some files/paths in the
+	staging area. These entities were being tracked before and later
+	were added in the `.gitignore`, due to which they show up in the
+	staging area.
+
+	To completely ignore and untrack files/paths falling in the above
+	category, it is advised to use `git rm --cached <file>` as well as
+	add these files/paths in the `.gitignore`.
+
 Hooks
 -----