git gitignore 只是不起作用。我无法忽略 .DS_Store 和 .gitignore 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21043132/
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
gitignore just doesn't work. I can't get it to ignore .DS_Store & .gitignore files
提问by deepng
I have .gitignore
d .DS_Store
and .gitignore
files. But still see them in the "git status".
我有.gitignore
d.DS_Store
和.gitignore
文件。但仍然在“git status”中看到它们。
Can someone explain to me how I can make sure that the files that I am trying to ignore don't show up while checking status?
有人可以向我解释如何确保我试图忽略的文件在检查状态时不显示吗?
git status
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .DS_Store
# .gitignore
I have the .DS_Store
file in all the subfolders of my repository. So I want all of those to be ignored. What should I do?
我的.DS_Store
存储库的所有子文件夹中都有该文件。所以我希望所有这些都被忽略。我该怎么办?
I have configured .gitignore
file in the root directory of my repository.
Should I copy this to all the subfolders for git to ignore these files?
Is adding .gitignore
in .gitignore
file not acceptable?
我已经.gitignore
在我的存储库的根目录中配置了文件。我应该将其复制到 git 的所有子文件夹以忽略这些文件吗?是增加.gitignore
在.gitignore
文件中不能接受的?
EDIT: Jan 21st 2014 ==================
编辑:2014 年 1 月 21 日 ==================
I still can't figure this out. The comments below didn't really help me. So I am reposting my query.
我仍然无法弄清楚这一点。下面的评论并没有真正帮助我。所以我重新发布我的查询。
Below is a snippet of my git status
output. The actually output spans couple of pages. And all the files in this output are files/folders I don't want in my repo. These are untracked files so I have never git add
ed them. But when I create a new project, I have to search for the related files/folders in this huge list before adding them, which is making the whole process a bit irritating.
下面是我的git status
输出片段。实际输出跨越几页。并且此输出中的所有文件都是我不想要的文件/文件夹。这些是未跟踪的文件,所以我从未git add
编辑过它们。但是当我创建一个新项目时,我必须在这个庞大的列表中搜索相关文件/文件夹才能添加它们,这使得整个过程有点烦人。
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# ../../.DS_Store
# ../../Classes/
# ../.DS_Store
# ../Basics/.DS_Store
# ../adt/.metadata/
# ../adt/Fundamentals/.classpath
# ../adt/Fundamentals/.project
# ../adt/Fundamentals/.settings/
# ../adt/Fundamentals/bin/
# .DS_Store
# .metadata/
Below is my .gitignore
file. Can someone please point out my mistake?
下面是我的.gitignore
文件。有人可以指出我的错误吗?
*.class
*.pyc
colors
**/.DS_Store
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
#Eclipse files
.project
# folders
.classpath/
.settings/
.metadata/
WEB-INF/lib/
META-INF/
Servers/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
回答by FSMaxB
- You shouldn't ignore your
.gitignore
. I don't think the ignore feature works when you don't have it in your repository. I'm not sure though. - Files that are already tracked won't be ignored, even if you add them to
.gitignore
. If you want them to be ignored after they've been added to the repository already, you have to remove them withgit rm filename
first.
- 你不应该忽略你的
.gitignore
. 当您的存储库中没有它时,我认为忽略功能不起作用。我不确定。 - 已经跟踪的文件不会被忽略,即使您将它们添加到
.gitignore
. 如果您希望在将它们添加到存储库后忽略它们,则必须先删除它们git rm filename
。
回答by gauteh
If you want to ignore a change to a file that is tracked by git you can specify to git that it should assume that the file has not changed:
如果您想忽略对 git 跟踪的文件的更改,您可以指定 git 它应该假设文件没有更改:
git update-index --assume-unchanged file
and to start tracking changes again do:
并再次开始跟踪更改,请执行以下操作:
git update-index --no-assume-unchanged file
if you have already added a file that should be completely ignored (.gitignore) you have to git rm
it first.
如果您已经添加了一个应该完全忽略的文件 (.gitignore),您必须先添加git rm
它。
reference: https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html
source: http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/
参考:https
: //www.kernel.org/pub/software/scm/git/docs/git-update-index.html来源:http: //blog.pagebakers.nl/2009/01/29/git-ignoring - 跟踪文件中的更改/
回答by Agis
This is what your .gitignore
should look like:
这就是你的.gitignore
样子:
.DS_Store
Also, the .gitignore
is meant to be tracked, ignoring it doesn't make sense. So after you've updated the file to contain just .DS_Store
do:
此外,.gitignore
旨在被跟踪,忽略它没有意义。因此,在您更新文件以包含之后,只需.DS_Store
执行以下操作:
$ git add .gitignore
$ git commit -m "Track .gitignore"
回答by Jakub Jirutka
Why you're ignoring .gitignore
? This doesn't make a sense. If you want to ignore some files just locally (i.e. don't track and publish this setting to the remote repository), then use .git/info/exclude
instead. Just add .DS_Store
to it, that's all.
你为什么不理.gitignore
?这没有意义。如果您只想在本地忽略某些文件(即不跟踪此设置并将其发布到远程存储库),请.git/info/exclude
改用。只需添加.DS_Store
它,仅此而已。
回答by Hogan
Add the lines
添加行
**/.DS_Store
**/.gitignore
回答by Ben Thielker
I had an issue getting .DS_Store
ignored where the problem was that it had already been committed to the repo. Removing it resolved the issue.
我有一个问题被.DS_Store
忽略了,问题是它已经提交给了回购。删除它解决了问题。
$ git rm --cached .DS_Store
回答by Lukasz Korzybski
I had the same exact issue on Mac OS X. I had .gitignore file in the repo but it just won't work.
我在 Mac OS X 上遇到了同样的问题。我在 repo 中有 .gitignore 文件,但它不起作用。
What was weird when I wanted to print the .gitignore content to the console with the cat
command it printed as it was empty. When opened with vim it appeared as normal.
当我想用它打印的命令将 .gitignore 内容打印到控制台时有什么奇怪的,cat
因为它是空的。当用 vim 打开时,它看起来很正常。
The solution was to remove the file, create a new one and put the content into it again. After that, ignoring files started to work and when I done cat .gitignore
it printed properly.
解决方案是删除文件,创建一个新文件并将内容重新放入其中。在那之后,忽略文件开始工作,当我完成cat .gitignore
它时打印正确。
回答by writecoffee
I experience the same issue. The solution is to add a .gitignore under your home directory first.
我遇到了同样的问题。解决方法是先在你的主目录下添加一个 .gitignore 。
My end the repository .gitignore no longer appears in indexing tracking.
我的最终存储库 .gitignore 不再出现在索引跟踪中。
回答by dylnmc
This is building off of Jakub Jirutka's response. I was a little confused upon first glance, but I tried it and it worked. Here is his answer stated - hopefully - more clearly.
这是建立在 Jakub Jirutka 的回应之上的。乍一看我有点困惑,但我试了一下,它奏效了。这是他的回答 - 希望 - 更清楚。
His answer put simply: store unwanted files in .git/info/exclude
(which is inside every git repository). Put each on a new line.
他的回答很简单:将不需要的文件存储在.git/info/exclude
(在每个 git 存储库中)。将每个放在一个新行上。
The .gitignore
file is useful to help ignore files and directories that you know are or will be generated but are unwanted. The fact that you can git add .gitignore
and then commit that and push it is really useful. When you clone this repository on another computer, for example, all of the files that should be ignored (after a ./configure; make; sudo make install;
, for example, usually generates example files and a lot of other links) willbe ignored (if they are in the .gitignore
.
该.gitignore
文件有助于忽略您知道已生成或将要生成但不需要的文件和目录。事实上,你可以git add .gitignore
提交并推送它真的很有用。例如,当您在另一台计算机上克隆这个存储库时,所有应该被忽略的文件(./configure; make; sudo make install;
例如,在 a 之后,通常会生成示例文件和许多其他链接)将被忽略(如果它们在.gitignore
.
However, sometimes, one is not sure whether a file is wanted in the repository or wants the file to just exist outside of git control as if it were in a non-git-controlled directory. This can be done by adding this to the exclude file inside of the exclude
file inside the .git/info
directory.
但是,有时,人们不确定存储库中是否需要某个文件,或者是否希望该文件仅存在于 git 控制之外,就好像它位于非 git 控制的目录中一样。这可以通过将其添加到目录内exclude
文件内的排除文件来完成.git/info
。
Every git repository has a .git folder. To completely exclude a file or directory, go to the good ole terminal, cd
to the root of the repository (i.e. cd src/best_repo_eva
). Then you will see a .git/
. Then, cd .git/info/
. There will probably only be one file there called exclude
. Use your favorite editor (just kidding; you may only use butterflies' wings to focus cosmic rays in the upper atmosphere to flip the correct bits in your drive platter ;) to edit the exclude
such that it contains the files you want to exclude on new lines.
每个 git 存储库都有一个 .git 文件夹。要完全排除文件或目录,请转到好的 ole 终端,cd
转到存储库的根目录(即cd src/best_repo_eva
)。然后你会看到一个.git/
. 然后,cd .git/info/
。那里可能只有一个名为exclude
. 使用您最喜欢的编辑器(开个玩笑;您只能使用蝴蝶的翅膀将宇宙射线聚焦在高层大气中以翻转驱动器盘片中的正确位;)编辑exclude
它,使其包含要在新行中排除的文件.
Easier solution: You have two files you want excluded: tmp1
and ignoreadf
更简单的解决方案:您有两个要排除的文件:tmp1
和ignoreadf
Go to terminal and...
转到终端并...
cd src/best_repo_eva
echo -e "tmp
tab\n ign
tab" >> .git/info/exclude
cd src/best_repo_eva
echo -e "tmp
tab\n ign
tab" >> .git/info/exclude
The tabs, obviously, only work if your terminal supports it. Note the -e
(supports backslash escapes) and the \n
(which is emphasized with a space) between the the two files.
显然,这些选项卡仅在您的终端支持时才有效。注意这两个文件之间的-e
(支持反斜杠转义)和\n
(用空格强调)。
Storing a lot of files with a similar ending, could be as easy as cd src/best_repo_eva
then echo -e $(ls -1 | grep "tmp") >> .git/info/exclude
(that's ls -ONE
not ls -L
- note that ls -a -1
doesn't work, unfortunately). That would store all files that contain the sequence "tmp" into the exclude file.
存储大量具有类似结尾的文件可能会像cd src/best_repo_eva
那时一样简单echo -e $(ls -1 | grep "tmp") >> .git/info/exclude
(这ls -ONE
不是ls -L
- 请注意ls -a -1
,不幸的是,这不起作用)。这会将包含序列“tmp”的所有文件存储到排除文件中。