Friday 28 December 2018

GIT: How can I ignore files that have already been committed to the repo?

Git can only ignore files that are untracked - files that haven't been committed to the repository, yet. That's why, when you create a new repository, you should also create a .gitignore file with all the file patterns you want to ignore.
However, of course, not everything goes perfect... and files slip through that you later would like to see ignored.

Preparing the Cleanup

Before cleaning up your repository, you should conduct two important preparations:
  1. Make sure your .gitignore file is up-to-date and contains all the correct patternsyou want to ignore.
  2. Commit or stash any outstanding local changes you might have. Your working copy should be clean before you continue.
TIP

How to Ignore Files

Our free online book explains the general process of how to ignore files in great detail.

Cleaning Ignored Files

In three steps, you can clean up your repository and make sure your ignored items are indeed ignored:
$ git rm -r --cached .
$ git add .
$ git commit -m "Clean up ignored files"

0 comments:

Post a Comment