Git commit -a“未跟踪的文件”?
当我执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
对于遇到同样问题的其他人,请尝试运行
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
git commit -am "msg"
与git add file
和git commit -m "msg"
不同,如果您有一些文件从未添加到 git 跟踪,您仍然需要执行
git add file
来源: “git commit -a”和“git add”
git commit -am "msg"
is not same asgit add file
andgit commit -m "msg"
If you have some files which were never added to git tracking you still need to do
git add file
Source: "git commit -a" and "git add"
您应该在命令行中输入
这将提交所有未跟踪的文件
编辑:
暂存文件后,它们已准备好提交,因此您的下一个命令应该是
You should type into the command line
This will commit all untracked files
Edit:
After staging your files they are ready for commit so your next command should be
如果您遇到未跟踪文件的问题,这个 3 行脚本将为您提供帮助。
然后只需
git push
If you are having problems with untracked files, this 3-line script will help you.
Then just
git push
首先您需要添加所有未跟踪的文件。使用此命令行:
git add *
然后使用此命令行提交:
git commit -a
或git commit -A
First you need to add all untracked files. Use this command line:
git add *
Then commit using this command line :
git commit -a
orgit commit -A
顾名思义,“未跟踪的文件”是 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'.
确保您位于本地 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.