gitignore not ignoring file

徘徊边缘 提交于 2019-11-27 00:27:21

问题


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


回答1:


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.




回答2:


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.




回答3:


One of the easy ways to ignore files on GitHub is perfectly explained here https://help.github.com/en/articles/ignoring-files

Before you do any push to GitHub, your project folder should be blank.

1) open terminal and write cd

and drag your project folder over terminal. After that it will look like this:

docmacbook$ cd /Users/docmacbook/Downloads/MyProjectFolder

2) Open .gitignore file and add files you want to ignore. For example my .gitignore file looks like this:

MyAppName.xcodeproj/xcuserdata
MyAppName.xcworkspace/xcuserdata
Pods
report.xml

3) Commit and Push to GitHub.

After this move your project or create a new one in the folder where .gitignore file is and now files you want to be ignored will not be pushed to your GitHub.

Note: These steps will work for an existing project too I think, did not tested.



来源:https://stackoverflow.com/questions/23716553/gitignore-not-ignoring-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!