xcode gitignore 不忽略文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23716553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:05:53  来源:igfitidea点击:

gitignore not ignoring file

xcodegitgitignore

提问by wcochran

No matter what I put in .gitignoreI can notget git to ignore the UserInterfaceState.xcuserstatefile below:

无论我输入什么,.gitignore我都无法让 git 忽略以下UserInterfaceState.xcuserstate文件:

$ 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 .gitignorefile listed on this post. I tried everything to match the pattern including the exact pathname: CalFoo.xcodeproj/project.xcworkspace/xcuserdata/wcochran.xcuserdatad/UserInterfaceState.xcuserstateto no avail.

我正在使用/编辑这篇文章中.gitignore列出的文件。我尝试了一切来匹配模式,包括确切的路径名:无济于事。CalFoo.xcodeproj/project.xcworkspace/xcuserdata/wcochran.xcuserdatad/UserInterfaceState.xcuserstate

This particular problem arises from the workflow where Xcode is used to create the initial git repo and the .gitignorefile from hereis 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).

这个特殊问题源于使用 Xcode 创建初始 git repo 并随后添加.gitignore来自此处的文件的工作流程。可以从这个问题中找到忽略 git 中先前跟踪的文件的更一般的答案(我想我从未在搜索中找到这篇文章,因为它的标题中没有“gitignore”)。

回答by michas

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

您只能忽略未版本控制的文件,但 git 已经知道该文件。

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

如果您希望 git 跟踪该文件,则无需告诉 git 忽略它。

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

如果您不希望 git 跟踪该文件的使用git rm,那么您的忽略规则将开始工作。

Caution: git rmwill remove the file.Use git rm --cachedto remove from the repo but not from the disk.

注意:git rm将删除文件。用于git rm --cached从 repo 中删除,但不从磁盘中删除。

回答by Gaurav Sharma

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.

要撤消 git rm --cached filename,请使用 git add filename。

回答by Doci

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

在 GitHub 上忽略文件的一种简单方法在这里得到了完美的解释 https://help.github.com/en/articles/ignoring-files

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

在对 GitHub 进行任何推送之前,您的项目文件夹应该是空白的。

1) open terminal and write cd

1) 打开终端并写入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:

2) 打开 .gitignore 文件并添加要忽略的文件。例如,我的 .gitignore 文件如下所示:

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

3) Commitand Pushto GitHub.

3)提交送到 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.

在此之后移动您的项目或在 .gitignore 文件所在的文件夹中创建一个新项目,现在您要忽略的文件将不会被推送到您的 GitHub。

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

注意:我认为这些步骤也适用于现有项目,但未经过测试。

回答by jameseronious

For me, I had to add my list to the xcode source control Ignored Files. setting -> source control -> git -> + in Ignored Files

对我来说,我必须将我的列表添加到 xcode 源代码控制忽略文件中。设置 -> 源代码控制 -> git -> + 在忽略文件中

xcode git ignoreFor good measure make sure to reset so the new git rules work.

xcode git 忽略为了更好的衡量,请确保重置以便新的 git 规则起作用。

git rm -r --cached .
git add .