Git的diff不能忽视的.gitignore指定文件 [英] Git diff doesn't ignore specified files in .gitignore

查看:659
本文介绍了Git的diff不能忽视的.gitignore指定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的git,我不知道我做错了。我想运行
    git的差异--name只
但我想排除在结束.TEST也就是说即使这些富人已经改变了,我不希望git的差异输出,它的更改的文件。
我试图将这些文件添加到的.gitignore文件,但一切确实是包括的.gitignore当我运行的git diff命令!

I'm new to git and I have no idea what I'm doing wrong. I want to run git diff --name-only but I want to exclude files ending in .test meaning that even if these haves have changed, I don't want git diff to output that it's changed. I tried to add these file to the .gitignore files but all that did is include .gitignore when I run the git diff command!

我是什么做错了,我如何排除文件,当我运行git的差异?

What am I doing wrong and how do I exclude files when I run git diff?

推荐答案

好吧,这是你做错了什么。 Git会继续跟踪这些​​文件,因为你已经开始在项目早期跟踪他们。在某些时候,前面所做的那样运行的初始提交看起来像:

Okay, This is what you did wrong. Git will continue to track those files because you already started tracking them earlier in your project. At some point earlier did you run an initial commit that looked like:

git add . # this added everything to the tracking system including your .test files
git commit -a -m 'I just committed everything in my project .test files included'

把事情是你gitignore文件将保留您进入您的项目创建.TEST哪一端未来的文件,但您需要删除您已经告诉混帐混帐从内存跟踪.TEST文件。在gitignore拉东西并不preform任何行动已查获的文件。你现在需要做的是这样的:

Putting things is your gitignore file will keep future files that you create which end in .test from entering your project, but you need to remove the .test files you already told git to track from git's memory. Pulling things in gitignore does not preform any action for already tracked files. What you need to do now is this:

# you can remove the files from gits tracking system and then put them back
# when you go to put them back now git will have no memory of tracking these
# and will consider future edits to be ignored
# Back your .test files up before doing this, and this will delete them from your project
git rm /path/to/your/file.test

选项2:

# this is safer but does not use gitignore at all
git update--index --assume-unchanged /path/to/your/file.test

当你运行选项2你告诉混帐,对于其余时间该文件是永远不会改变(即使它在现实生活中一样)这让你保持你的.TEST文件作为跟踪项目的一部分(因为它们是现在),但混帐永远不会再打扰过你关于变更。注意,此操作可以在任何时间被撤消,而不是破坏性的,这就是为什么它更安全。你也应该去阅读它,你使用它之前。

When you run option 2 you are telling git that for the rest of time that file is never changing (even when it does in real life) This let you keep your .test files as part of your tracked project (as they are now), but git will never bother you about changes to them ever again. Note that this operation can be undone at any time and is not destructive, which is why it is safer. Also you should go read up on it before you use it.

<一个href=\"https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html\">https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html

这篇关于Git的diff不能忽视的.gitignore指定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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