为什么学习练习会警告 git commit -am 不足以将我的新 .gitignore 添加到存储库,即使 git 明确添加了它?
Why does a learning exercise warn that git commit -am is insufficient to add my new .gitignore to the repository even though git clearly added it?
我正在学习git已经来到this exercise:
Commit the .gitignore
file to your repository. Hint: Running git 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-commit 的手册页:
-a
--all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
因此该命令仅记录对已跟踪文件的更改。
您所做的 "correctly"(不是 "wrongly")是您使用 git add
添加新文件。
我正在学习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-commit 的手册页:
-a --all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
因此该命令仅记录对已跟踪文件的更改。
您所做的 "correctly"(不是 "wrongly")是您使用 git add
添加新文件。