.gitignore
is used to ignore only non-crawled files, that is, since a git add
is used to track file changes, .gitignore
can not ignore these files.
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details. ( link )
If you have not done commit
yet, use:
-
git reset <arquivo-ou-diretório>
If you've already done commit
, use:
-
git rm --cached <arquivo>
-
git rm -r --cached <diretório>
git-rm - Remove files from the working tree and from the index
-r
Allow recursive removal when a leading directory is given.
- cached
Use this option to unstage and remove paths only from the index. Working
tree files, if modified or not, will be left alone.
There is also a third situation that may be of interest to some, where git maintains a copy of the file and to perform updates on it. (useful for maintaining a template file when working as a team)
-
git update-index --assume-unchanged <arquivo-ou-diretório>
git-update-index - Register file contents in the working tree to the index
- [no-] assumes-unchanged
When this flag is specified, the object names recorded for the paths are not updated. Instead, this option sets / unsets the "takes unchanged" bit for the paths. When the "assumes unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat (2) system call (eg cifs).
Git will fail (gracefully) in case it needs to modify this file in the index eg when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
Source: link