====== シナリオに沿ったコマンドサンプル ====== ====== サンプルシナリオ ====== ===== 共有サーバで空のリポジトリ作成 ===== [root@a4 tmp]# mkdir share.git [root@a4 tmp]# cd share.git/ * init:初期化 * bare:作業ファイルがない、管理情報だけのリポジトリ。共有サーバのリポジトリは一般的にこれ。 [root@a4 share.git]# git init --bare Initialized empty Git repository in /tmp/share.git/ [root@a4 share.git]# ll 合計 32 -rw-r--r-- 1 root root 23 2月 5 16:16 HEAD drwxr-xr-x 2 root root 4096 2月 5 16:16 branches -rw-r--r-- 1 root root 66 2月 5 16:16 config -rw-r--r-- 1 root root 73 2月 5 16:16 description drwxr-xr-x 2 root root 4096 2月 5 16:16 hooks drwxr-xr-x 2 root root 4096 2月 5 16:16 info drwxr-xr-x 4 root root 4096 2月 5 16:16 objects drwxr-xr-x 4 root root 4096 2月 5 16:16 refs [root@a4 share.git]# ===== A環境での新規登録 ===== [root@a3 tmp]# mkdir local01 [root@a3 tmp]# cd local01/ * clone:どこかのリポジトリから丸ごと取得する。ユーザを指定する場合はIPアドレスの前に記述([[user@192.168.80.124]]) [root@a3 local01]# git clone ssh://192.168.80.124/tmp/share.git . Cloning into '.'... warning: You appear to have cloned an empty repository. [root@a3 local01]# echo "This is test page" > test.html * add:gitの管理下に追加。または、更新ファイルの登録。 [root@a3 local01]# git add . * commit:ローカルリポジトリにコミット [root@a3 local01]# git commit -m "1st" [master (root-commit) 490258d] 1st 1 file changed, 1 insertion(+) create mode 100644 test.html * push:共有リポジトリにコミット。cloneしてpushの場合はpush先の指定がなくてもいいが、指定はあったほうがいいという声も。 [root@a3 local01]# git push No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master'. fatal: The remote end hung up unexpectedly error: failed to push some refs to 'ssh://192.168.80.124/tmp/share.git' * 共有リポジトリが初期化直後の場合など、単純なpushではエラーになる場合は「origin master」のオプションをつける(リモートトラッキングブランチ) [root@a3 local01]# git push origin master Counting objects: 3, done. Writing objects: 100% (3/3), 217 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To ssh://192.168.80.124/tmp/share.git * [new branch] master -> master [root@a3 local01]# ===== B環境での取得 ===== [root@a3 tmp]# mkdir local02/ [root@a3 tmp]# cd local02 [root@a3 local02]# git clone ssh://192.168.80.124/tmp/share.git . Cloning into '.'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. * log:コミットログを確認 [root@a3 local02]# git log commit 490258d5074c2ba42d255304daa910c98337f09f Author: hanako Date: Tue Feb 5 16:23:54 2013 +0900 1st [root@a3 local02]# ===== A環境でファイル更新 ===== [root@a3 local01]# sed -i "s/page/page./" ./test.html [root@a3 local01]# git add . [root@a3 local01]# git commit -m "2nd" [master ef59fac] 2nd 1 file changed, 1 insertion(+), 1 deletion(-) [root@a3 local01]# git push Counting objects: 5, done. Writing objects: 100% (3/3), 244 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To ssh://192.168.80.124/tmp/share.git 490258d..ef59fac master -> master [root@a3 local01]# ===== B環境でコンフリクト対応 ===== [root@a3 local02]# sed -i "s/page/page../" ./test.html [root@a3 local02]# git add . [root@a3 local02]# git commit -m "2nd" [master 68939fb] 2nd 1 file changed, 1 deletion(-) create mode 100644 master * コミット→コンフリクト\\ Bの更新前にAが更新してしまったため、対象ファイルが重複している [root@a3 local02]# git push To ssh://192.168.80.124/tmp/share.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'ssh://192.168.80.124/tmp/share.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. * 最新にして状況確認 [root@a3 local02]# git pull remote: Counting objects: 5, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ssh://192.168.80.124/tmp/share 151d58f..c09e03f master -> origin/master Auto-merging test.html CONFLICT (content): Merge conflict in test.html Automatic merge failed; fix conflicts and then commit the result. * コンフリクトの状況確認\\ 「=」が境で、上がローカルリポジトリの内容(自分の作業内容)、下が共有リポジトリの内容 [root@a3 local02]# git diff diff --cc test.html index 765542b,ad0a3a4..0000000 --- a/test.html +++ b/test.html @@@ -1,1 -1,1 +1,5 @@@ ++<<<<<<< HEAD +This is test page.. ++======= + This is test page. ++>>>>>>> c09e03fad4dc99a3edcfa2563d0e6121783a1720 : * 対象ファイルを修正して、再度add→commit→push [root@a3 local02]# vi test.html [root@a3 local02]# git add . [root@a3 local02]# git commit -m "2nd" [master a844f10] 2nd [root@a3 local02]# git push Counting objects: 8, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (4/4), 355 bytes, done. Total 4 (delta 1), reused 0 (delta 0) To ssh://192.168.80.124/tmp/share.git c09e03f..a844f10 master -> master [root@a3 local02]# ===== A環境で情報更新 ===== [root@a3 local01]# git pull remote: Counting objects: 8, done. remote: Compressing objects: 100% (2/2), done. remote: Total 4 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. From ssh://192.168.80.124/tmp/share c09e03f..a844f10 master -> origin/master Updating c09e03f..a844f10 Fast-forward test.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)