gitignore not ignoring file

git, gitignore, xcode

Solution

You can only ignore unversioned files but that file is already known to git.

If you want git to track that file, there is no need to tell git to ignore it.

If you don't want git to track that file use `git rm` and your ignore rule will start working.

Caution: `git rm` will remove the file. Use `git rm --cached` to remove from the repo but not from the disk.

Problem

No matter what I put in `.gitignore` I can not get git to ignore the `UserInterfaceState.xcuserstate` file below: ``` $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: .gitignore modified: CalFoo.xcodeproj/project.xcworkspace/xcuserdata/wcochran.xcuserdatad/UserInterfaceState.xcuserstate ``` I am using/editing the `.gitignore` file listed on this post. I tried everything to match the pattern including the exact pathname: `CalFoo.xcodeproj/project.xcworkspace/xcuserdata/wcochran.xcuserdatad/UserInterfaceState.xcuserstate` to no avail. This particular problem arises from the workflow where Xcode is used to create the initial git repo and the `.gitignore` file from here is added afterwards. A more general answer to ignoring previously tracked files in git can be found from this question (I guess I never found this post in my search since it didn't have "gitignore" in the title).

Original source

Related problems