【问题标题】:git .ignore not working in a directorygit .ignore 不在目录中工作
【发布时间】:2011-08-27 04:41:51
【问题描述】:

我有以下 .gitignore 文件

# file named .gitignore

system/application/config/database.php
system/application/config/config.php
system/logs
modules/recaptcha/config/*

但是,当我在 config 和 recapcha.php 中添加任何更改时,git status 会警告我如下。 当我向 database.php 添加任何更改时。它没有在状态中显示它

shin@shin-Latitude-E5420:/var/www/myapp$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   modules/recaptcha/config/recaptcha.php
#   modified:   system/application/config/config.php
#
no changes added to commit (use "git add" and/or "git commit -a")

我该如何解决这个问题?

提前致谢。

我在 Ubuntu 11.04 上使用 git 版本 1.7.5.1

【问题讨论】:

标签: git


【解决方案1】:

文件已存储在您的本地提交树中。您需要先将它们从存储库中删除。这可以通过以下方式完成:

git rm --cached system/application/config/config.php modules/recaptcha/config/recaptcha.php

之后,您需要再提交一次,然后就可以开始了。

【讨论】:

  • 谢谢。 git rm 删除了一个文件。但是添加 --cached 解决了这个问题。如果我想再次添加它,我需要做什么?我只需要从 .gitignore 文件中取出吗?
  • 太棒了。谢谢
【解决方案2】:

执行以下操作以触发 gitignore

第 1 步: 在你想要修复的仓库中提交所有待处理的更改并推送。

第 2 步: 现在您需要从 git 索引中删除所有内容以刷新您的 git 存储库。这是安全的。使用这个命令:

git rm -r --cached .

第 3 步: 现在您需要将所有内容重新添加到 repo 中,这可以使用以下命令完成:

git add .

第 4 步: 最后,您需要使用以下命令提交这些更改:

git commit -m "Gitignore issue fixed"

【讨论】:

  • 谢谢!最简单快捷的方法。
  • 这非常有效!就这么简单。非常感谢@NandaGopal
  • 这正是我所需要的,并挽救了我的一天。谢谢
【解决方案3】:

如果您的文件在您将目录添加到 .gitignore 之前已经在 git 中,那么 git 将继续跟踪它。如果您不想要它,请先执行“git rm”将其删除。

【讨论】:

  • 不会git rm(没有--cached)也删除文件吗?还是因为它列在.gitignore 文件中而离开它?
  • 您可能应该在以前的某个地方备份它。在您 rm 并提交后,将其复制回来。但是我不知道 --cached 选项,我会看看它。
【解决方案4】:

我猜你的 .gitignore 不在你的工作树的根目录中。

如果你将 .gitignore 放在与 system/application/config/config.php 相同的目录中,你就可以使用

echo config.php >> system/application/config/.gitignore

路径是相对于当前目录的(或者:.gitignore 是一个每个目录排除/包含文件)。

见 man git-ignore

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-03
    • 2014-12-07
    • 2016-06-05
    • 1970-01-01
    • 2013-10-13
    • 2015-07-03
    • 2016-06-16
    • 1970-01-01
    相关资源
    最近更新 更多