为什么我的新.gitignore会自动忽略? [英] Why is my new .gitignore automatically ignored?

查看:464
本文介绍了为什么我的新.gitignore会自动忽略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,在将我的资源库转换为git并执行第一个构建之后,一些构建目录出现在 git status 中:

 #分支大师
#已更改但未更新:
#(使用git add< file> ...来更新将会更新的内容提交)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:build.xml
#修改:src / ant / common-tasks.xml

#未记录文件:
#(使用git add< file> ...来包含将要提交的内容)

#classes /
#doku /
#texdoku /
#tmp /

因此,我当然需要一个 .gitignore ,并且由于我不想再次输入这些目录名,我使用这个命令:

  git status -s | grep'?'| cut -b 4-> .gitignore 

由于 git status -s 显示这

  M build.xml 
M src / ant / common-tasks.xml
??班/
?? doku /
?? texdoku /
?? tmp /

之前,我假定新的 .gitignore

 类/ 
doku /
texdoku /
tmp /

但是:

  $ git status 
#分支主
#已更改但未更新:
#(使用git add< file> ...更新内容将被提交)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:build.xml
#modified:src / ant / common-tasks.xml

没有更改添加到提交中(使用git add和/或git commit -a)

是的,它忽略了四个目录,而且还忽略了新的 .gitignore 文件。为什么?

  $ git add .gitignore 
您的.gitignore文件之一会忽略以下路径:
.gitignore
如果您真的想添加它们,请使用-f。
致命:没有添加文件

呵呵。为什么我的 .gitignore 被忽略?我记得在上一个项目中,我可以将其添加到存储库。我搜索了很长一段时间,并搜索了什么可能会导致此文件被忽略 - .git / info / excludes 只有注释行,并且所有父目录高达 / 没有 .gitignore 。另外 git config core.excludesfile 不会显示任何内容。



为什么?

解决方案

  git status -s | grep'?'| cut -b 4-> .gitignore 

> .gitignore 重定向在管道的末端创建 .gitignore 文件之前 git状态做了它的目录列表。所以,实际上结果是

  .gitignore 
类别/
doku /
texdoku /
tmp /

写入 .gitignore 文件。因此, .gitignore 忽略了它自己。当然,编辑文件删除第一行解决了问题。


So, after converting my repository to git and doing the first build, some build directories showed up in git status:

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   build.xml
#       modified:   src/ant/common-tasks.xml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       classes/
#       doku/
#       texdoku/
#       tmp/

So, of course I need a .gitignore, and since I didn't want to type these directory-names again, I used this command:

git status -s | grep '?' | cut -b 4- > .gitignore

Since git status -s showed this

 M build.xml
 M src/ant/common-tasks.xml
?? classes/
?? doku/
?? texdoku/
?? tmp/

before, I assumed the new .gitignore file to contain these lines:

classes/
doku/
texdoku/
tmp/

But then:

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   build.xml
#       modified:   src/ant/common-tasks.xml
#
no changes added to commit (use "git add" and/or "git commit -a")

Yes, it ignored the four directories, but also the new .gitignore file. Why?

$ git add .gitignore
The following paths are ignored by one of your .gitignore files:
.gitignore
Use -f if you really want to add them.
fatal: no files added

Huh. Why is my .gitignore ignored? I remember that in the last project I could add it to the repository. I searched quite a time, and googled what else could cause this file to be ignored - .git/info/excludes has only commented lines, and all parent-directories up to / have no .gitignore. Also git config core.excludesfile shows nothing.

Why?

解决方案

git status -s | grep '?' | cut -b 4- > .gitignore

The > .gitignore redirection at the end of the pipeline created the .gitignore file before git status did its directory listing. So, in fact the result was

.gitignore
classes/
doku/
texdoku/
tmp/

which got written in the .gitignore file. Thus, the .gitignore ignored itself. Editing the file to remove the first line solved the problem, of course.

这篇关于为什么我的新.gitignore会自动忽略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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