Sourcetree中的.gitignore文件无法正常工作 [英] .gitignore file in Sourcetree not working

查看:162
本文介绍了Sourcetree中的.gitignore文件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个maven项目,我想忽略生成并存储在我的项目(评估)根文件夹的/ target文件夹中的文件。在我的git仓库的根目录中,我有一个.gitignore文件,其中包含以下内容(后端只是一个包含eclipse项目评估的文件夹)

I am working on a maven project and I want to ignore the files generated and stored in the /target folder of my project (Evaluation) root folder.In the root of my git repository I have a .gitignore file with the following entries (backend is just a folder which contains the eclipse project Evaluation)

backend/Evaluation/logs/
backend/Evaluation/target/

由于某些原因,SourceTree不会忽略存储在这两个文件夹中的文件,编译我的项目有一些未提交的更改,它们是/ target文件夹中的一些.class文件。

For some reason SourceTree does not ignore the files stored in these two folders and when I compile my project there are some uncommitted changes which are some .class files inside the /target folder.

为什么会发生这种情况?我还尝试将.gitignore条目更改为

Why is this happening ? I also tried to change the .gitignore entries to


/ backend / Evaluation / logs / **

/backend/Evaluation/logs/**

但它不起作用。

有什么想法?

推荐答案

假设我们有一个文件无意中添加到我们的存储库中:

Let's say we have a file that was inadvertently added to our repository:

stackoverflow$ echo this file is important > junkfile
stackoverflow$ git add junkfile
stackoverflow$ git ci -m 'added a file'

在某些时候,我们意识到该文件并不重要,因此我们将它添加到 .gitignore 文件中:

At some point, we realize that the file is unimportant so we add it to our .gitignore file:

stackoverflow$ echo junkfile >> .gitignore
stackoverflow$ git ci -m 'ignore junkfile' .gitignore

稍后,我们对该文件进行了一些更改:

Later on, we make some changes to that file:

stackoverflow$ sed -i 's/ is / is not/' junkfile 

当然,即使文件列在 .gitignore ,我们已经告诉git我们要跟踪它,所以 git status 显示:

And of course, even though the file is listed in .gitignore, we have already told git that we want to track it, so git status shows:

stackoverflow$ git status
# On branch 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:   junkfile
#
no changes added to commit (use "git add" and/or "git commit -a")

我们需要从存储库中删除此文件(不从我们的工作树中删除文件)。我们可以通过 --cached 标志对 git rm 执行此操作:

We need to remove this file from the repository (without removing the file from our work tree). We can do this with the --cached flag to git rm:

stackoverflow$ git rm --cached junkfile
rm 'junkfile'

此阶段是删除操作...

stackoverflow$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    junkfile
#

...所以我们需要提交它:

...so we need to commit it:

stackoverflow$ git commit -m 'removed junkfile from repository'
[master 19f082a] removed junkfile from repository
 1 file changed, 1 deletion(-)
 delete mode 100644 junkfile



Now if we run git status git will ignore this file:

stackoverflow$ git status
# On branch master
nothing to commit, working directory clean

即使它仍在我们的工作树中:

Even though it's still here in our working tree:

stackoverflow$ cat junkfile 
this file is not important

这篇关于Sourcetree中的.gitignore文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆