The .gitignore file is very useful in ignoring some of the files that we don't want to control. Unfortunately, it cannot be used when the file is already under version control. For example, my .gitignore (which is already added to git) file might be different than what my coworker wants it to be (e.g. I want to ignore Vim files). Whenever I make changes to this file, git shows it as a modified file. So my questions:
- Is there any way to ignore changes for a certain file, which is already controlled by Git?!
- Is there any way to commit these changes, but keep it for myself only? Obviously, I don't want to use a branch, because I am working on a certain branch.
I've written about three ways of excluding files elsewhere.
In summary:
The lower items in the list have priority over the higher items, and a
!
in front of an item in any of the patterns in the file reverses a previous exclusion.This paradigm is seen elsewhere in Git. For example, if you were using submodules, the url to the submodule to use is in the the
.gitmodules
file in the repository, but you can over-ride the url to use in the .git/config file.If you want to exclude files that are specific to your process (such as Vim temporary files), edit the (local) file
.git/info/exclude
and add your exclusion patterns there. This file is designed for developer-specific exclusions rather than.gitignore
, which is designed for project-wide exclusions.The short summary is, everybody should agree on what is added to
.gitignore
. For files where you don't agree, use.git/info/exclude
.you can use this command to get you want.
or
This will only remove the track from git, will not delete the real files.
Then you can edit the ignore file to untrack these files or dirs.
I cannot really answer the general question (having Git ignore tracked files) - it strikes me as a feature that would be much more detrimental than useful.
However, the gitignore manual page specifies a few ways to configure patterns for excluded files.
In particular, it gives explicit instructions on how to use these various ways:
Meaning that your
.gitignore
file should not be different from your coworkers - it is working as intended.There you have it. Specify a
core.excludesfile
file path into your~/.gitconfig
file, and then put into it the patterns that you want to exclude.Use git-update-index to temporarily ignore changes to files that are already under version control:
To undo that use:
Also have a look at the
skip-worktree
andno-skip-worktree
options for update-index if you need this to persist past a git-resetHere is a generalized, ubiquitos (not individual) solution for those using Git under SmartGitHG viusal interface: