git - 忽略 Sourcetree 中已提交的文件

标签 git atlassian-sourcetree sourcetree

我对 git 还很陌生。由于我不需要公开可用的存储库,因此我选择了 Bitbucket。我使用 Atlassian Sourcetree 作为我的桌面客户端。

我正在使用 Eclipse IDE 开发一个 Java 项目。就像每个人一样,我不需要类文件在更改的文件中可见,但是这些文件已经提交并 pull 入我的远程存储库。
现在,每当我对 .java 文件进行更改时,我需要 SourceTree 不将这些类文件显示为已更改的文件。

正如我通过这么多问题和答案所了解的那样,仅 .gitignore 文件中的条目不能简单地忽略类文件,因为它们已经被提交和 pull 。
为此,据我了解,我应该做的是忽略源树中的文件并提交它。那么只有 .gitignore 文件中的条目才能满足我们的需要。 (这是我的理解,如有错误请指正)。

我现在的问题是,ignore选项是灰色的;因此,作为解决方案,社区建议首先选择“停止跟踪”选项,然后选择“忽略”选项。但是当我停止跟踪时,没有出现任何变化。
根据社区,该文件应标有蓝色图标。但我的情况并非如此。尽管我没有更改图标,但我还是尝试选择忽略选项。但它仍然是灰色的。即使完成这些步骤后,当我对 .java 文件进行更改时,.class 文件也会出现在已更改的文件列表中。

这里出了什么问题?为什么我没有完成工作?我做错了什么?

最佳答案

What my problem now is, the ignore option is grayed out; so as a solution for that the community suggest to first select the Stop Tracking option and then select the ignore option.

根据“What is the difference between Stop Tracking and Discard File in git SourceTree”:

You should use Stop Tracking.
After this, if you see the file listed in Unstaged files, you can use right-click > Ignore... in SourceTree to update your .gitignore file to ignore the file in future.

在您的情况下,不要将文件逐一添加到 .gitignore 中,而是在存储库的根目录中编辑 .gitignore 并添加:

*.class

关于git - 忽略 Sourcetree 中已提交的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39971532/

相关文章:

git - 如何使用 SourceTree 将指定的提交 rebase 到不同的分支?

git - 在 git submodule/repository 中只放置一个文件

git push 到 gitlab ssh 失败

python - git-德威奇 :how to merge or rebase?

ios - xcode 源代码树和 bitbucket

SourceTree:不断询问 bitbucket.org 的密码

git - 如何将分支从一个存储库移动到不同存储库的另一个分支

git - 我应该在开发完成之前 merge dev 和 master 分支吗?

atlassian-sourcetree - GitKraken 和 SourceTree,代码隐私?

git - 使用gitflow删除一个 'feature'分支而不 merge 到master分支