Git 提交-一个“未追踪的文件”?

当我做 git commit -a的时候,我会看到下面的内容:

  # Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch better_tag_show
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   ../assets/stylesheets/application.css
# modified:   ../views/pages/home.html.erb
# modified:   ../views/tags/show.html.erb
# modified:   ../../db/seeds.rb
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# ../assets/stylesheets/
# ../views/pages/

那些未追踪的文件是什么意思?所有的变化都确实被跟踪了。我不明白为什么 Git 要警告我这里有未追踪的文件。

编辑:

好吧,我看到很多混乱的答复。这是什么发生后,我 git commit -a这一点。

# On branch master
nothing to commit (working directory clean)

正如您所看到的,除了应用了更改的那四个文件之外,没有其他东西。

我的问题应改写如下: 当提交中的所有更改都已被跟踪时,为什么 git 要警告我未跟踪文件?

换句话说,Git 提交消息 < em > 中的未跟踪警告是否不必要?

295491 次浏览

git commit -am "msg"不同于 git add filegit commit -m "msg"

如果你有一些文件,从来没有添加到 git 跟踪你仍然需要做 git add file

“ gitcommit-a”命令是实现两步过程的快捷方式 你修改一个已经被回购的文件,你仍然必须 告诉回收人员,“嘿! 我想把这个添加到舞台文件和 这是通过发出“ git add”来完成的 command. “git commit -a” is staging the file and committing it in one 台阶。

资料来源: “ git commit-a”和“ git add”

顾名思义,“未被跟踪的文件”指的是那些没有被 git 跟踪的文件。它们不在您的暂存区域中,也不是以前任何提交的一部分。如果您希望对它们进行版本控制(或由 git 管理) ,可以通过使用“ git add”告诉“ git”来实现。检查 Progit书中的这一章 记录对存储库的更改,它使用了一个很好的视觉,提供了一个很好的解释,关于记录变化的 git 回购,也解释了术语’跟踪’和’取消跟踪’。

对于其他有同样问题的人,尝试跑步

git add . 它会将工作目录的所有文件添加到跟踪(包括未跟踪) ,然后使用

提交所有跟踪文件。

As suggested by @Pacerier, one liner that does the same thing is

git add -A

您应该在命令行中键入

git add --all

这将提交所有未跟踪的文件

编辑:

在准备好文件之后,它们就可以提交了,因此您的下一个命令应该是

git commit -am "Your commit message"
  1. 首先,您需要添加所有未跟踪的文件:

    git add *

  2. 然后使用以下命令行提交:

    git commit -a

如果您有问题与未跟踪的文件,这3行脚本将帮助您。

git rm -r --cached .
git add -A
git commit -am 'fix'

Then just git push

确保您在本地 git 的正确目录(存储库主文件夹)中,这样它就可以找到。在提交或添加文件之前进行 git 文件夹配置。