22

In Xcode I noticed that .DS_Store and *.xcuserstate always change and don't need to be commited. So, I wrote a .gitignore file that contains this:

.DS_Store
*.xcuserstate

among other entries. Then I used:

git rm --cached *xcuserstate
git rm ---cached .DS_Store

To remove the these file types already under version control. However, when I go to merge Xcode tells me that there are changes that need to be committed. Those changes include .DS_Store files and .xcuserstate files.

So, I tried this:How can I Remove .DS_Store files from a Git repository?

find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
find . -name *.xcuserstate -print0 | xargs -0 git rm --ignore-unmatch

and I got the same result. How do I remove these files from source control for good?

Community
  • 1
  • 1
Bryan Bryce
  • 1,052
  • 1
  • 13
  • 25
  • I was committing the changes from Xcode and making the changes in the command line. For some reason Xcode wasn't committing properly. After explicitly committing from the command line it finally worked. I made the change to both branches that I want to merge, but now Xcode is telling me that I can't merge because, "The file .gitignore had a tree conflict." – Bryan Bryce Feb 19 '14 at 03:20
  • Once again, the command line worked. I merged using the command line and everything worked fine. – Bryan Bryce Feb 19 '14 at 03:27

2 Answers2

27

You need to commit your change after removing them from the staging area.

As you did already, run:

$ git rm --cached path/to/.DS_Store
$ git rm --cached *.xcuserstate

Note, you may have some in other directories, so you may need several invocations to get them all. At this point, your removals are staged in the index, but there's still more to do: add your .gitignore, and commit the final result:

$ git add .gitignore
$ git commit -m "Remove and ignore .xcuserstate and .DS_Store files."

Now they'll be removed from the repository, and ignored in the future. Note: this will remove the files for other people, even though you used git rm --cached locally. Unfortunately, there isn't much you can do about this. Also, the files are still in your history, so depending on what you do, you may see them in other branches until things get merged and all your branches are based on something that has the new commit.

John Szakmeister
  • 38,342
  • 9
  • 78
  • 72
  • 2
    You can also use git rm --cached *.DS_Store to find and remove all .DS_Store files in the project. – Bruno Delgado Oct 28 '15 at 19:31
  • 3
    You probably need to wrap that in quotes to keep the shell from expanding it and letting git do that honor. Plus, I generally avoid that kind of tactic because you might be tempted to use it at other times and accidentally delete files you didn't intend. But if you're careful, it is useful. – John Szakmeister Oct 29 '15 at 10:31
3

Try git update-index --assume-unchanged *.xcuserstate .DS_Store and see if it helps

user376507
  • 1,654
  • 1
  • 14
  • 25
  • Git will not recognize them as changed and it won't prompt you to commit them. – user376507 Feb 19 '14 at 03:20
  • The problem is Xcode and OS X change these files all the time, so Xcode thinks it constantly needs to be re-committed. – Bryan Bryce Feb 19 '14 at 03:29
  • Even if they change, once you do `git update-index --assume-unchanged *.xcuserstate .DS_Store` , git will assume that nothing has changed in these files. – user376507 Feb 19 '14 at 03:34