Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore not ignoring file

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).

like image 292
wcochran Avatar asked May 17 '14 22:05

wcochran


People also ask

Why is .gitignore not ignoring my files?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them. Igal S.

Why isn't my Gitignore working?

The Solution To resolve the problem remove from the repository the tracked files contained in the . gitignore file. To achieve this use “git rm” to remove and untrack all the files in the repository, then use “git add” to re-add all the files (the files contained in the .

How do I force git to ignore a file?

Use Git update-index to ignore changes Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.

How do I ignore a text file in Gitignore?

You have the option to use double Asterisk (**) to match any number of directories and files. For example, Test/**/*. txt will tell git to ignore only files ending with . txt in the test directory and its subdirectories.


2 Answers

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.

like image 184
michas Avatar answered Oct 03 '22 00:10

michas


I had same problem.

First commit any outstanding code changes, and then, run this command:

git rm -r --cached . 

This removes any changed files from the index(staging area), then just run:

git add . 

Commit it:

git commit -m ".gitignore working now" 

To undo git rm --cached filename, use git add filename.

like image 27
Gaurav Sharma Avatar answered Oct 03 '22 00:10

Gaurav Sharma