リポジトリを作る
対象のディレクトリに移動して
$ git init Initialized empty Git repository in /home/ats/public_html/.git/
これで対象ディレクトリに「.git」という隠しファイルができ、このファイル以下でGit関連の管理をしているようです。
ステータス確認
addしただけではまだコミットされていません。今の状態を確認します。
$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: index.html #
(「q」でquitするよ)
コミット
$ git commit -m "Initial conttents of public_html" --author="yourname <youremal@example.com>" Created initial commit 79a357b: Initial conttents of public_html 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 index.html
コミット作成者を設定する
$ git config user.name "yourname" $ git config user.email "youremail@example.com"
コミット時のエディタ設定
$ export GIT_EDITOR=vim
そしてコミット
$ git commit index.html Created commit b5eeb1f: Convert to HTML 1 files changed, 5 insertions(+), 0 deletions(-)
※commit コマンドのあと、コミット時のメッセージを記入します。
ログ確認
git log
$ git log commit b5eeb1fbd43ee45f0240c1771fa599b6ab3d4706 Author: yourname <youremail@example.com> Date: Sat Apr 2 22:43:57 2011 +0900 Convert to HTML commit 79a357b8a565c6f936aa8fa52dd59a0da4ad3d12 Author: yourname <youremail@example.com> Date: Sat Apr 2 22:36:13 2011 +0900 Initial conttents of public_html
ログの詳細表示
git show コミットID
(コミットIDを省略すると最新の1件を表示)
$ git show b5eeb1fbd43ee45f0240c1771fa599b6ab3d4706 commit b5eeb1fbd43ee45f0240c1771fa599b6ab3d4706 Author: yourname <youremail@example.com> Date: Sat Apr 2 22:43:57 2011 +0900 Convert to HTML diff --git a/index.html b/index.html index 34217e9..5e39be7 100644 --- a/index.html +++ b/index.html @@ -1 +1,6 @@ +<html> +<body> My website is alive! +</body> +</html> +
ログを1行表示
git show-branch --more=
$ git show-branch --more=10 [master] Convert to HTML [master^] Initial conttents of public_html
差分を見る
git diff 古いバージョンのコミットID 新しいバージョンのコミットID
$ git diff 79a357b8a565c6f936aa8fa52dd59a0da4ad3d12 b5eeb1fbd43ee45f0240c1771fa599b6ab3d4706 diff --git a/index.html b/index.html index 34217e9..5e39be7 100644 --- a/index.html +++ b/index.html @@ -1 +1,6 @@ +<html> +<body> My website is alive! +</body> +</html> +
削除
git rm ファイル名
$ git rm poem.html rm 'poem.html'
※rm するファイルはあらかじめリポジトリにコミットしておくこと。
$ git commit -m "Remove a poem" Created commit b3ac4a5: Remove a poem 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 poem.html
rm からの commit
ファイル名変更
git mv 変更前 変更後 $ git mv foo.html bar.html $ git commit -m "Moved foo to bar" Created commit bb8e145: Moved foo to bar 1 files changed, 0 insertions(+), 0 deletions(-) rename foo.html => bar.html (100%)
リポジトリのコピーを作る
$ cd ~ $ git clone public_html my_website Initialized empty Git repository in /home/ats/my_website/.git/
設定ファイル
$ git config -l core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true user.name=yourname user.email=youremail@example.com
$ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [user] name = yourname email = youremail@example.com
エイリアスを設定する
$ git config --global alias.show-graph 'log --graph --abbrev-commit --pretty=oneline' $ git show-graph * bb8e145... Moved foo to bar * 1a5208b... git mv test * b3ac4a5... Remove a poem * b829c91... git rm test * b5eeb1f... Convert to HTML * 79a357b... Initial conttents of public_html