Use git-update-index to temporarily ignore changes to files that are already under version control:
git update-index --assume-unchanged <files>
To undo that use:
git update-index --no-assume-unchanged <files>
Also have a look at the skip-worktree
and no-skip-worktree
options for update-index if you need this to persist past a git-reset
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.
git rm --cached path/to/file
or
git rm -r --cached path/ignore/dir
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:
- Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that all developers will want to ignore) should go into a
.gitignore
file.
Meaning that your .gitignore
file should not be different from your coworkers - it is working as intended.
Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow) should go into the
$GIT_DIR/info/exclude
file.Patterns which a user wants git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by
core.excludesfile
in the user’s~/.gitconfig
.
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.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With