git add
でステージ(舞台)に乗せておいたファイルの状態を歴史に記録すること。
git status
でステージ済みか否かを確認する。
git commit
で歴史に記録されるのは、ステージに乗せたその時のファイル内容であり、あくまでgit add
した瞬間のものなのであって、git commit
した瞬間ではない。
#!/bin/bash
# 一時ディレクトリを作り直す
rm -fr git-tmp; mkdir git-tmp; cd git-tmp
# スクリプト表示しながら実行
set -v
#--------------------------------------
# リポジトリ作成: repo
mkdir repo
cd repo
git init
#--------------------------------------
# 追跡するファイル
echo 'A' >> abc
echo 'X' >> xyz
git add abc xyz
git commit -m 'コミット1'
#--------------------------------------
# 追跡していないファイル
touch 非追跡ファイル 無視ファイル
echo '無視ファイル' >> .gitignore
#--------------------------------------
# ステージに乗せる
echo 'B' >> abc
echo 'Y' >> xyz
git add abc xyz
# ステージ後に変更
echo 'C' >> abc
# リポジトリの状態
git status
#--------------------------------------
# コミット
git commit -m 'コミット2'
# リポジトリの状態
git status
#
cat abc
#-------------------------------------- # リポジトリ作成: repo mkdir repo cd repo git init Initialized empty Git repository in /home/alice/git-tmp/repo/.git/ #-------------------------------------- # 追跡するファイル echo 'A' >> abc echo 'X' >> xyz git add abc xyz git commit -m 'コミット1' [master (root-commit) d09ae49] コミット1 2 files changed, 2 insertions(+) create mode 100644 abc create mode 100644 xyz #-------------------------------------- # 追跡していないファイル touch 非追跡ファイル 無視ファイル echo '無視ファイル' >> .gitignore #-------------------------------------- # ステージに乗せる echo 'B' >> abc echo 'Y' >> xyz git add abc xyz # ステージ後に変更 echo 'C' >> abc # リポジトリの状態 git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: abc # modified: xyz # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: abc # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .gitignore # 非追跡ファイル #-------------------------------------- # コミット git commit -m 'コミット2' [master 75e066e] コミット2 2 files changed, 2 insertions(+) # リポジトリの状態 git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: abc # # 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") # cat abc A B C