Git commit -a“未跟踪文件”?

问题描述 投票:65回答:6

当我做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 commit消息中未跟踪的警告是否不必要?

git
6个回答
83
投票

对于有相同问题的其他人,请尝试运行

git add .将添加当前目录的所有文件进行跟踪(包括未跟踪)然后使用

git commit -a提交所有跟踪文件。

正如@Pacerier所建议的那样,一个做同样事情的班轮是

git add -A


27
投票

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

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

“git commit -a”命令是两步过程的快捷方式。在修改了repo已知的文件后,你仍然要告诉回购,“嘿!我想将它添加到暂存文件并最终提交给你。“这是通过发出”git add“命令完成的。 “git commit -a”正在暂存文件并一步提交。

资料来源:"git commit -a" and "git add"


7
投票
  1. 首先,您需要添加所有未跟踪的文件。使用此命令行: git add *
  2. 然后使用此命令行提交: git commit -a

6
投票

您应该键入命令行

git add --all

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


2
投票

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

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

然后只是git push


1
投票

顾名思义,“未跟踪文件”是git未跟踪的文件。它们不在您的临时区域,并且不属于任何先前的提交。如果你想让它们被版本化(或由git管理)你可以通过使用'git add'来告诉'git'。在Recording Changes to the Repository书中查看本章Progit,该书使用了一个很好的视觉效果来提供关于记录git repo变化的良好解释,并解释术语“跟踪”和“未跟踪”

© www.soinside.com 2019 - 2024. All rights reserved.