繁体   English   中英

.gitignore 被 Git 忽略

[英].gitignore is ignored by Git

我的.gitignore文件似乎被 Git 忽略了 - .gitignore文件是否已损坏? Git 期望哪种文件格式、语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

来自git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决这个问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

每当我遇到 git 正在跟踪.gitignore列出的文件的情况时,我使用以下内容:

git update-index --skip-worktree <file_name>

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

我的.gitignore文件似乎被Git忽略了.gitignore文件是否已损坏? Git需要哪种文件格式,语言环境或文化?

我的.gitignore

# This is a comment
debug.log
nbproject/

git status输出:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       debug.log
#       nbproject/
nothing added to commit but untracked files present (use "git add" to track)

我希望debug.lognbproject/不会出现在未跟踪的文件列表中。

我应该从哪里着手解决此问题?

看到有几个人已经回答过了,不知道有没有说清楚。 就我而言,问题是使用 echo 命令创建 .gitignore 文件。 在这种情况下,文件编码已更改,我必须打开文本文件,单击另存为并将底部选项卡中的编码更改为 UTF-8。 当使用 touch 命令创建文件并通过文本编辑器编辑其内容时,.gitignore 没有出现问题。

这里有很多答案,但对我有用的并不完全适用于任何特定的答案,我正在以一种简单的方式一一记下需要在这里完成的所有步骤:

Pre --- 备份 repo 以防万一。 (我没有,但可能会让你感觉更安全)

  1. 确保这是你的第一次提交还是更早的这些文件被添加并因此被缓存。
  2. 如果是,则 git rm -r --cached 。 和 git add 。 (不要错过点)
  3. 如果还是不行,用记事本打开文件
  4. 转到文件 - >另存为
  5. 将编码更改为 ANSI。 (有些答案错误地说 UTF-8 ,但它不起作用并且不必要地浪费时间)
  6. 再次 git rm -r --cached 。 和 git add 。 (不要错过点)
  7. 现在做 Git status 并验证我们想要的已经发生

这可能听起来很傻,但什么解决我的问题是认识到.gitignore正常工作,即使它说deleted: yourfile上git的状态。

我打算忽略一个错误日志文件,忽略我造成的任何错误,但保存其他开发人员造成的错误,以防有一天他们在调试一个奇怪的问题时派上用场。 但是,git 不会让您“忽略”并同时保留文件。

我希望它“及时冻结”,但 git 说它要么被跟踪,要么根本不允许在那里。

PhpStorm(可能还​​有其他一些 IDE 用户) ,就我而言,问题是我通过查找器在项目外创建并添加了文件。

我删除了那个,然后在 PhpStorm 项目中重新创建了相同的一个,右键单击 -> 新建 -> 文件,它立即生效。

我的 30 美分技巧:

  1. 请清理您的目录。 git clean -f (我试过git rm -r --cached .但它对我不起作用。)

警告: git clean -f 将删除未跟踪的文件,这意味着它们将永远消失,因为它们没有存储在存储库中。 在执行此操作之前,请确保您确实要删除所有未跟踪的文件。

也许您可以尝试git clean -xdf删除被忽略的目录和未跟踪的文件

  1. 现在将HEAD带到当前位置git reset HEAD --hard
  2. 检查git status

  3. 现在创建.gitignore在我的情况下想要忽略名为data的文件夹。 所以我写了/data/ (最初的/用于文件/文件夹,后来的/仅用于文件夹)。

  4. 现在执行 git add、提交和推送。

尽管在这篇文章和其他文章中尝试了各种建议(例如Gitignore 不工作gitignore 不工作 - 被忽略? )我无法让 git 忽略我的 .gitignore.txt 文件中包含的文件/文件夹。

在尝试创建 .gitignore.txt 文件的不同方法后,我设法弄清楚如何让它工作,尽管我不能说我理解为什么.gitignore.txt 。 知道是否有人可以提供解释会很有趣。

为了那些也可能发现以前的答案没有解决他们的问题的人的利益,我将描述我尝试过的方法、无效的方法以及有效的方法。 希望这样做也可以阐明原因 请注意,我使用的是 Windows 10。

尝试 #1(失败)

在 Windows 资源管理器中创建新的 txt 文件:

  1. (在项目文件夹中)右键->新建->文本文档
  2. 将文件名更改为“.gitignore”
  3. 在 Notepad++ 中打开文件,输入的文件/目录名称将被忽略
  4. 编码 -> ANSI [注 1],保存更改

我运行git status但我想忽略的文件/文件夹显示为未跟踪。 我在 Windows 资源管理器中检查了文件属性。 正如预期的那样,文件名是“.gitignore”,文件类型是“文本文档( .txt )”。

注 1

一些贡献者表示编码必须是 ANSI(而不是 UTF)。 在 Notepad++ 中,我发现无论我是否执行编码 -> ANSI 或编码 -> 转换为 ANSI + 保存,关闭文件并重新打开它(在 Notepad++ 中),当我检查编码时,它总是报告 UTF- 8. 最终工作的 .gitignore.txt 文件也是如此。

尝试#2(失败)

在 Notepad++ 中创建新的 txt 文件:

  1. 在 Notepad++ 创建的新文件中,输入要忽略的项目
  2. 保存为“.gitignore.txt”,将“保存类型”从“普通文本文件”(默认)更改为“所有类型”,并取消勾选“附加扩展名”框(默认勾选)。

我运行git status并且和以前一样,所有文件/目录都列在未跟踪的文件下。 和以前一样,文件名是“.gitignore”,文件类型是“文本文档( .txt )”。

尝试#3(成功)

在 Notepad++ 中仍然打开相同的文件 (.gitignore.txt):

  1. Save as ".gitignore" 为"Save as type"选择了"Normal text file",这会自动勾选"Append extension"

我注意到创建的文件在 Windows 资源管理器中似乎没有名称。 我检查了文件的属性:文件名字段为空,文件类型为“文本文档( .gitignore )”。

我运行git status ,这次我想忽略的文件/文件夹没有列为未跟踪文件 -成功!

在 Notepad++ 中打开文件我注意到编码是 UTF-8,并且文件名被标识为“.gitignore”(与 Windows 资源管理器中不同)。

因此,创建 txt 文件的方式似乎有些微妙。 也许这是 Windows 独有的特性?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM