Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Ignoring Version-Controlled Files

Tags:

git

gitignore

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:

  1. A global git ignore file applies to all repositories on that system
  2. The .gitignore file in the repository applies the the repository and all clones of that repository.
  3. The .git/info/exclude file applies only to that repository.

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.