我正在学习git,来到this exercise :
Commit the
.gitignore
file to your repository. Hint: Runninggit commit -am
isn’t enough. Why not?
我已经完成了git commit -am
,这似乎已经足够了。
michael@michael:~/repos/website$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: breaching_whale.jpg
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
michael@michael:~/repos/website$ git add .
michael@michael:~/repos/website$ ls
images index.html README.md
michael@michael:~/repos/website$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
deleted: breaching_whale.jpg
michael@michael:~/repos/website$ git commit -am "Add gitignore"
[master e7cc08c] Add gitignore
2 files changed, 1 insertion(+)
create mode 100644 .gitignore
delete mode 100644 breaching_whale.jpg
michael@michael:~/repos/website$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
您能否推测我做错了什么,并帮助我理解教程中的含义以及为什么 git commit -am
还不够?
最佳答案
这并不是您做错了什么。 git commit -am
将所有跟踪的文件添加到提交中,并将消息作为参数提供给 m
。在此命令之前,您已经(可能自动)执行了 git add . ,该命令还将未跟踪的文件从当前目录添加到提交中。
为了清楚起见,跟踪文件是 Git 已经在监视更改的文件,而未跟踪文件是 Git 可以看到存在但没有历史记录的文件。仅单独运行 git commit -a 不会将新文件添加到存储库,而只是将更改提交到 Git 已经知道的文件。
关于git - 为什么学习练习会警告 git commit -am 不足以将我的新 .gitignore 添加到存储库,即使 git 明确添加了它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36514530/