Ste*_*eSt 63 git atlassian-sourcetree sourcetree
我正在开发一个maven项目,我想忽略生成并存储在我的项目(Evaluation)根文件夹的/ target文件夹中的文件.在我的git存储库的根目录中,我有一个带有以下条目的.gitignore文件(后端)只是一个包含eclipse项目评估的文件夹)
backend/Evaluation/logs/
backend/Evaluation/target/
Run Code Online (Sandbox Code Playgroud)
由于某种原因,SourceTree不会忽略存储在这两个文件夹中的文件,当我编译项目时,会有一些未提交的更改,这些更改是/ target文件夹中的一些.class文件.
为什么会这样?我还尝试将.gitignore条目更改为
/后端/评估/日志/**
但它也没有用.
有任何想法吗 ?
mfg*_*cha 125
因为问题中有Sourcetree标签,我会回答你如何使用Sourcetree做到这一点,它非常简单.
如前所述,首先必须从跟踪中删除文件,然后使Sourcetree忽略该文件.
lar*_*sks 98
假设我们有一个无意中添加到我们的存储库的文件:
stackoverflow$ echo this file is important > junkfile
stackoverflow$ git add junkfile
stackoverflow$ git ci -m 'added a file'
Run Code Online (Sandbox Code Playgroud)
在某些时候,我们意识到该文件并不重要,所以我们将它添加到我们的.gitignore
文件中:
stackoverflow$ echo junkfile >> .gitignore
stackoverflow$ git ci -m 'ignore junkfile' .gitignore
Run Code Online (Sandbox Code Playgroud)
稍后,我们对该文件进行了一些更改:
stackoverflow$ sed -i 's/ is / is not/' junkfile
Run Code Online (Sandbox Code Playgroud)
当然,即使列出了文件.gitignore
,我们已经告诉git我们要跟踪它,所以git status
显示:
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")
Run Code Online (Sandbox Code Playgroud)
我们需要从存储库中删除此文件(不从我们的工作树中删除该文件).我们可以使用以下--cached
标志执行此操作git rm
:
stackoverflow$ git rm --cached junkfile
rm 'junkfile'
Run Code Online (Sandbox Code Playgroud)
这使delete
操作阶段...
stackoverflow$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: junkfile
#
Run Code Online (Sandbox Code Playgroud)
......所以我们需要承诺:
stackoverflow$ git commit -m 'removed junkfile from repository'
[master 19f082a] removed junkfile from repository
1 file changed, 1 deletion(-)
delete mode 100644 junkfile
Run Code Online (Sandbox Code Playgroud)
现在,如果我们运行git status
git将忽略此文件:
stackoverflow$ git status
# On branch master
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
即使它仍在我们的工作树中:
stackoverflow$ cat junkfile
this file is not important
Run Code Online (Sandbox Code Playgroud)
小智 11
我在跟踪bin文件夹时遇到问题(整个文件夹).
所以这里是快速步骤(更直观,因为我更像是一个视觉类型的人):
我希望这可以帮助别人.
tfm*_*gue 11
如果文件已经添加或提交到您的Git存储库,则必须先停止跟踪它们,然后才能被.gitIgnore忽略.
要停止在SourceTree中跟踪文件:
右键单击文件.选择"停止跟踪".
(这不会删除你的文件,只是停止跟踪它们)
要停止从命令行跟踪文件:
git rm --cached example.txt
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
87642 次 |
最近记录: |