- 共有リポジトリを生成する方法
cd ~
mkdir shareRepo
cd shareRepo/
git init --bare --shared
//Initialized empty shared Git repository in /Users/ユーザ/shareRepo/
初期化のテキストが表示されてリポジトリ初期化終了
- ローカルリポジトリの生成
cd ..
mkdir localRepo
cd localRepo/
git clone ../shareRepo/
//warning: You appear to have cloned an empty repository.
空のリポジトリを生成したとテキストが表示される。
- 最初に設定しておく設定(コミットする際に登録される情報のため)
git config --global user.name tsukasa
git config --global user.email addiction@gmail.com
//設定ファイルが反映されているか確認
git config --global --list
- ローカルリポジトリにファイルを追加
cd ~/localRepo/shareRepo/
echo 'hello git' > index.html
git add .
git commit -m "first Commit"
//[master (root-commit) 62e746a] first Commit
// file changed, 1 insertion(+)
//create mode 100644 index.html
コミットのメッセージが出力される
- コミットしたファイルの確認
git log
//commit 62e746aee8a3663f0ed803062034b58d4428f691
//Author: tsukasa <tsukasa@example.com>
//Date: Tue Apr 8 17:11:41 2014 +0900
//
// first Commit
- ローカルリポジトリで修正したファイルを共有リポジトリに反映する
git push origin master
//Counting objects: 3, done.
//Writing objects: 100% (3/3), 218 bytes | 0 bytes/s, done.
//Total 3 (delta 0), reused 0 (delta 0)
//To /Users/tsukasa/localRepo/../shareRepo/
// * [new branch] master -> master
- 新しくローカルリポジトリを生成して反映の確認
cd ~/
mkdir localRepo2
cd localRepo2/
git clone ../shareRepo/
//Cloning into 'shareRepo'...
//done.
cd shareRepo/
ls
//index.html
- ファイルの修正(登録時と同じ)
//localRepo/index.htmlを修正したのち
git status
//On branch master
//Your branch is up-to-date with 'origin/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: index.html
//
//no changes added to commit (use "git add" and/or "git commit -a")
git add .
git commit -m "index.html modify"
git push origin master
- 共有リポジトリからの修正分取得
cd ~//localRepo2/shareRepo
git pull
//Updating 2f37587..5db4623
//Fast-forward
//index.html | 2 ++
//1 file changed, 2 insertions(+)
- 修正したファイルの差分チェック
git diff
//diff --git a/index.html b/index.html
//index 1c5d9a9..821a6b2 100644
//--- a/index.html
//+++ b/index.html
//@@ -1,3 +1,5 @@
// hello git
//
// ユーザー1が修正しました(修正テキスト)
//+
//+ユーザー2が修正しました(追加テキスト)
- 復元
//最新のものに復元 HEADの代わりにコミットIDを入れれば、指定したIDのファイル戻る
git reset --hard HEAD^