Git commit -a“未跟踪的文件”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8470547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git commit -a "untracked files"?
提问by disappearedng
When I do a git commit -a
, I am seeing the following:
当我做 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/
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.
那些未跟踪的文件是什么意思?所有的变化都确实被跟踪了。我不明白为什么 git 在这里警告我未跟踪的文件。
EDIT:
编辑:
Ok I see a lot of confused replies. This is what happens after I git commit -a
this.
好的,我看到很多困惑的回复。这就是我git commit -a
这之后发生的事情。
# 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?
我的问题应该改写如下:当此提交中的所有更改都已被跟踪时,为什么 git 会警告我有关未跟踪文件的信息?
In other words, is the untracked warning in the git commit message unnecessary?
换句话说,git commit 消息中的未跟踪警告是不必要的吗?
回答by coding_idiot
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 add .
这会将当前目录的所有文件添加到跟踪(包括未跟踪)然后使用
git commit -a
to commit all tracked files.
git commit -a
提交所有跟踪的文件。
As suggested by @Pacerier, one liner that does the same thing is
正如@Pacerier 所建议的,一个做同样事情的班轮是
git add -A
git add -A
回答by zengr
git commit -am "msg"
is not same as git add file
and git commit -m "msg"
git commit -am "msg"
不等于git add file
和git commit -m "msg"
If you have some files which were never added to git tracking you still need to do git add file
如果您有一些从未添加到 git tracking 的文件,您仍然需要这样做 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.
“git commit -a”命令是两步过程的快捷方式。在你修改了一个 repo 已知的文件后,你仍然需要告诉 repo,“嘿!我想将此添加到暂存文件中,并最终提交给您。” 这是通过发出“git add”命令来完成的。“git commit -a”正在暂存文件并一步提交。
Source: "git commit -a" and "git add"
回答by Travis Delly
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"
回答by Mohamad
First you need to add all untracked files. Use this command line:
git add *
Then commit using this command line :
git commit -a
首先,您需要添加所有未跟踪的文件。使用这个命令行:
git add *
然后使用此命令行提交:
git commit -a
回答by AliFurkan
If you are having problems with untracked files, this 3-line script will help you.
如果您遇到未跟踪文件的问题,这个 3 行脚本将帮助您。
git rm -r --cached .
git add -A
git commit -am 'fix'
Then just git push
那么就 git push
回答by sateesh
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 Repositoryin the Progitbook 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 管理),您可以通过使用 'git add' 告诉 'git' 来实现。在Progit书中查看这一章Recording Changes to the Repository,它使用漂亮的视觉效果很好地解释了记录对 git repo 的更改,并解释了术语“已跟踪”和“未跟踪”
回答by einarc
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.
确保您位于本地 git 中的正确目录(存储库主文件夹)中,以便它可以在您提交或添加文件之前找到 .git 文件夹配置。