リポジトリ作成

gitリポジトリは.git/を持つただのディレクトリにすぎないから、ディレクトリ名を変えたりまるごとコピーしたり、他の場所やLinuxに移動しても、そこでgitコマンドが使えれば引き続き動作する。

流れを確認するシェルスクリプト

  1. リポジトリ作成
  2. いくつかコミットし、コミットログ確認
  3. ディレクトリ(リポジトリ)名を変更し、コミットログ確認
#!/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