将新条目添加到.gitignore不起作用 [英] Adding new entries to .gitignore doesn't work

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

问题描述

如果我理解正确,为了忽略"文件,以便在键入git statusgit add -A时不会出现该文件,我需要将其添加到.gitignore文件中.

If I understand right, in order to "ignore" a file so it won't come up when I type git status or git add -A I need to add it to the .gitignore file.

我的目标是永久性地将更改提交到Git时忽略某个文件夹和文件.

My goal is to ignore a certain folder and file when committing changes to Git, permanently.

我尝试在编辑器中编辑.gitignore文件:

I tried editing the .gitignore file in my editor:

config/
src/package.xml

我保存了文件,提交并推送到Git,从另一个存储库刷新了我的项目,键入了git status,仍然看到了xml文件和文件夹.

I saved the file, committed and pushed to Git, refreshed my project from another repository, typed git status and still saw the xml file and the folder.

还尝试通过选择放弃更改"来使用GItHub Desktop,它会自动添加到.gitignore中,并包含以下几行:

Also tried using GItHub Desktop by choosing "Discard Changes", it automatically added to .gitignore the following lines:

*.sublime-workspace
config/.local_store
*.sublime-workspace
src/package.xml

但结果相同...

项目结构:

          Full
    ________|____________
   |        |            |
config  .gitignore      src
   |                     |
  ...                package.xml

推荐答案

.gitignore不适用于追溯.仅当第一次将文件添加到存储库时,git add会读取该文件.

.gitignore doesn't apply retroactively. It is read by git add only when a file is added for the first time to the repo.

如果文件已经在存储库中,将其列出在gitignore中是不够的.您还需要将其从存储库(git rm --cached src/package.xml)中删除.

If the file is already in the repo, listing it in gitignore is not enough. You also need to remove it from the repo (git rm --cached src/package.xml).

别忘了git add .gitignoregit commit,以保留更改.

Don't forget to git add .gitignore and git commit, in order to persist the changes.

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

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