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

发布于 2024-12-20 15:00:48 字数 1069 浏览 1 评论 0原文

当我执行 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 提交中的未跟踪警告消息不必要

When I do a git commit -a, I am seeing the following:

  # 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/

What does those untracked files mean? All the changes have been indeed tracked. I don't understand why git is warning me about untracked files here.

EDIT:

Ok I see a lot of confused replies. This is what happens after I git commit -a this.

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

As you can see, there is NOTHING other than those four files that had changes applied.

My question should be rephrased as follows: Why is git warning me about untracked files when all of the changes in this commit has been tracked?

In other words, is the untracked warning in the git commit message unnecessary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

っ左 2024-12-27 15:00:48

对于遇到同样问题的其他人,请尝试运行

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

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

正如 @Pacerier 所建议的,执行相同操作的一个衬垫是

git add -A

For others having the same problem, try running

git add .
which will add all files of the current directory to track (including untracked) and then use

git commit -a to commit all tracked files.

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

git add -A

小苏打饼 2024-12-27 15:00:48

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

如果您有一些文件从未添加到 git 跟踪,您仍然需要执行 git add file

“git commit -a”命令是两步过程的快捷方式。后
您修改了存储库已知的文件,您仍然需要
告诉仓库,“嘿!我想将其添加到暂存文件中并且
最终还是交给你了。”这是通过发出“git add”来完成的
命令。 “git commit -a”正在暂存文件并将其一次提交
步骤。

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

git commit -am "msg" is not same as git add file and git commit -m "msg"

If you have some files which were never added to git tracking you still need to do git add file

The “git commit -a” command is a shortcut to a two-step process. After
you modify a file that is already known by the repo, you still have to
tell the repo, “Hey! I want to add this to the staged files and
eventually commit it to you.” That is done by issuing the “git add”
command. “git commit -a” is staging the file and committing it in one
step.

Source: "git commit -a" and "git add"

紫罗兰の梦幻 2024-12-27 15:00:48

您应该在命令行中输入

git add --all

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

编辑:

暂存文件后,它们已准备好提交,因此您的下一个命令应该是

git commit -am "Your commit message"

You should type into the command line

git add --all

This will commit all untracked files

Edit:

After staging your files they are ready for commit so your next command should be

git commit -am "Your commit message"
心奴独伤 2024-12-27 15:00:48

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

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

然后只需git push

If you are having problems with untracked files, this 3-line script will help you.

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

Then just git push

债姬 2024-12-27 15:00:48
  1. 首先您需要添加所有未跟踪的文件。使用此命令行:

    git add *

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

    git commit -agit commit -A

  1. First you need to add all untracked files. Use this command line:

    git add *

  2. Then commit using this command line :

    git commit -a or git commit -A

摇划花蜜的午后 2024-12-27 15:00:48

顾名思义,“未跟踪的文件”是 git 未跟踪的文件。它们不在您的暂存区域中,也不属于任何先前提交的一部分。如果您希望对它们进行版本控制(或由 git 管理),您可以通过使用“git add”告诉“git”来实现。查看本章记录对存储库的更改Progit 书中,它使用漂亮的视觉效果来提供关于记录 git repo 的更改以及解释术语“已跟踪”和“未跟踪”的一个很好的解释。

As the name suggests 'untracked files' are the files which are not being tracked by git. They are not in your staging area, and were not part of any previous commits. If you want them to be versioned (or to be managed by git) you can do so by telling 'git' by using 'git add'. Check this chapter Recording Changes to the Repository in the Progit book which uses a nice visual to provide a good explanation about recording changes to git repo and also explaining the terms 'tracked' and 'untracked'.

夏见 2024-12-27 15:00:48

确保您位于本地 git 中的正确目录(存储库主文件夹)中,以便在提交或添加文件之前可以找到 .git 文件夹配置。

Make sure you're in the right directory (repository main folder) in your local git so it can find .git folder configuration before you commit or add files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文