$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# sample.txt
nothing added to commit but untracked files present (use "git add" to track)
履歴の追跡対象になっていないファイルとして、sample.txtがあります。一度インデックスに登録すると、追跡対象に登録することができます。
ファイルをインデックスに登録するにはaddコマンドを使用します。<file>はインデックスに登録するファイルを指定します。スペース区切りで複数指定することもできます。
$ git add
パラメータに「.」を指定すると、すべてのファイルをインデックスに登録することができます。
$ git add .
それでは、sample.txtをインデックスに追加して確認してみます。
$ git add sample.txt
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: sample.txt
#
インデックスにsample.txtが追加され、コミットの準備が整いました。 次はcommitコマンドを実行してコミットします。commitコマンドのフォーマットは次のとおりです。
$ git commit -m "<file>"
commitコマンドを実行してから状態を確認します。
$ git commit -m "first commit"
[master (root-commit) 116a286] first commit
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 sample.txt
$ git status
# On branch master
nothing to commit (working directory clean)
これで、コミットされていない変更はなくなりました。
リポジトリの変更履歴を確認してみましょう。リポジトリの変更履歴を表示するにはlogコマンドを使用します。
$ git status
# On branch master
nothing to commit (working directory clean)