git init
すると、.git/
ができる。
git
コマンドを使い、歴史を記録していく。
.git/
に格納されていく。ここは基本的に直接触らない。
git add
してからgit commit -m 'コミット・メッセージ'
。
git log
。
gitリポジトリは.git/
を持つただのディレクトリにすぎないから、ディレクトリ名を変えたりまるごとコピーしたり、他の場所やLinuxに移動しても、そこでgit
コマンドが使えれば引き続き動作する。
#!/bin/bash
# 一時ディレクトリを作り直す
rm -fr git-tmp; mkdir git-tmp; cd git-tmp
# スクリプト表示しながら実行
set -v
#--------------------------------------
# リポジトリ作成: repo
mkdir repo
cd repo
#
git init
# .git/
ls .git/
#--------------------------------------
# コミット: A
echo 'A' >> abc
#
git add abc
git commit -m 'A'
# コミット: X
echo 'X' >> abc
echo 'X' >> xyz
#
git add abc xyz
git commit -m 'X'
# コミット: B
echo 'B' >> abc
#
git add abc
git commit -m 'B'
# コミットの履歴
git --no-pager log --oneline --graph
#--------------------------------------
# リポジトリ(ディレクトリ)名を変更
cd ..
mv repo/ test/
cd test/
# コミットの履歴
git --no-pager log --oneline --graph
#-------------------------------------- # リポジトリ作成: repo mkdir repo cd repo # git init Initialized empty Git repository in /home/alice/git-tmp/repo/.git/ # .git/ ls .git/ HEAD branches config description hooks info objects refs #-------------------------------------- # コミット: A echo 'A' >> abc # git add abc git commit -m 'A' [master (root-commit) c7803b3] A 1 file changed, 1 insertion(+) create mode 100644 abc # コミット: X echo 'X' >> abc echo 'X' >> xyz # git add abc xyz git commit -m 'X' [master 3cbacf5] X 2 files changed, 2 insertions(+) create mode 100644 xyz # コミット: B echo 'B' >> abc # git add abc git commit -m 'B' [master c5517bc] B 1 file changed, 1 insertion(+) # コミットの履歴 git --no-pager log --oneline --graph * c5517bc B * 3cbacf5 X * c7803b3 A #-------------------------------------- # リポジトリ(ディレクトリ)名を変更 cd .. mv repo/ test/ cd test/ # コミットの履歴 git --no-pager log --oneline --graph * c5517bc B * 3cbacf5 X * c7803b3 A