2016-04-09 6 views
2

私はgitのを勉強していますし、this exerciseに来た:はなぜ学習運動は、Gitは-amはgitのは明らかにこれを追加していてもリポジトリに私の新しい.gitignoreを追加するには不十分であるコミットと警告していますか?

リポジトリに.gitignoreファイルをコミットします。ヒント:Running git commit -amでは不十分です。何故なの?

私はgit commit -amを行っており、これで十分だと思われます。

[email protected]:~/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") 
[email protected]:~/repos/website$ git add . 
[email protected]:~/repos/website$ ls 
images index.html README.md 
[email protected]:~/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 

[email protected]:~/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 
[email protected]:~/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は十分ではありませんでしたか?

答えて

2

これは、あなたが何か間違ったことをしたのケースではありません。 git commit -amは、追跡されたすべてのファイルをパラメータとして与えられたメッセージと共にコミットに追加します。m。このコマンドの前にgit add .を(おそらく自動的に)実行しています。これは、未追跡のファイルをカレントディレクトリからコミットまで追加します。

明確にするために、追跡されたファイルは、Gitはすでに人跡未踏のファイルながら変化を監視しているファイルはGitが見ることができる何かが存在しますが、のない歴史を持っていないです。 git commit -aを単独で実行するだけで、新しいファイルがリポジトリに追加されることはありませんが、Gitがすでに知っているファイルに変更をコミットするだけです。

1

gitのコミットのmanページから:

-a --all

あなたが言われていない自動的に変更され、削除されたファイルをステージングするコマンドを知らせるが、新しいファイルGitは影響を受けません。

のでコマンドは、既にファイルを追跡するために変更を記録します。 あなたが「正しく」(ない「誤って」)でした新しいファイルを追加するためにgit addを使用したことは何ですか。

関連する問題