.gitignore不起作用 [英] .gitignore does not work

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

问题描述

我的回购根存在一个 .gitignore 文件。 .gitignore 文件具有以下模式来排除已编译的Python文件,这是文件中的唯一行。

I've a .gitignore file at the root of my repo. The .gitignore file has the following pattern to exclude the compiled Python files and that is the only line in the file.

*.pyc

现在当我执行以下操作时:回购的根。

Now when i do the following at the root of the repo.

git init
git add . 
git status 

它表明它仍然跟踪 .pyc 文件并尝试将其添加为新文件。请参阅下面的输出。

It shows that it still tracks the .pyc file and tries to add it as new file. See output below.

系统信息:Windows 7,cygwin

System info: Windows 7, cygwin

注意:此问题明显不是关于被忽略的文件已被跟踪。我还在 .gitignore 文件中尝试了DOS和Unix风格的行结尾。

Note: This issue is CLEARLY not about the ignored file being already tracked. I also tried both DOS- and Unix-style line endings on the .gitignore file.

git status 给出:

git status gives:

# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   .gitignore
#   new file:   feedapp/__init__.py
#   new file:   feedapp/appconfig.py
#   new file:   feedapp/appconfig.pyc

如何解决这个问题?

推荐答案

.gitignore 仅适用于 untracked 文件。如果您正在跟踪 .pyc ,那么 .gitignore 不适用。使用 git rm 移除 .pyc ,并在下次执行 git status 它(以及任何其他)不会出现在未跟踪文件列表中,也不会自动添加。

.gitignore only applies to untracked files. If you are tracking a .pyc then .gitignore won't apply. Remove the .pyc with git rm and next time you do a git status it (and any others) won't show up in the list of untracked file and nor will it be automatically added.

否则,如果您需要忽略已受版本控制的文件,请更新索引以忽略对已受版本控制的文件所做的更改:

Otherwise if you need to ignore a file already under version control, update the index to ignore changes to files already under version control:

git update-index --assume-unchanged <files>

欲了解更多信息,请参阅 git-update-index(1)手册页 相关答案 .gitignore文件不会忽略 相关问题的答案( GIT:忽略版本控制文件

For more information please see git-update-index(1) Manual Page, the related answer to .gitignore file not ignoring and the related answer to question (GIT: Ignoring Version-Controlled Files).

这篇关于.gitignore不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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