fc2ブログ

リポジトリ共有時のトラブル解決

リポジトリ共有時のトラブル解決

#22 共有時のトラブルを解決する
http://dotinstall.com/lessons/basic_git/6722
を参考に、
共有ゆえに起こるトラブルの解決方法の学習

これは共有であるために起きるトラブルとして
ありえるのが
ユーザBが編集し commit までしたことを知らず
ユーザAが同じ場所を編集し
このためコンフリクトが発生して
エラーがでる
というもの

とりあえず、実践したほうがわかりやすかったので
cd ~/myweb2/

ディレクトリを移動して
vim index.html
で最終行へ
share test
と記述して保存

git add.
git commit -m "share test added"
git push origin master

で変更した内容を共有リポジトリに送ります
ここまでは問題なしです

次に、ユーザA体験をします
cd ~/myweb
で移動して
vim index.html

share start !
と追記して保存します

そして、今回は git add と git commit を同時に行います

git commit -am "shared start"
というように
git commit のオプションに
-am
をつけるだけです

実際に git commit までできているか確認するには
git log
とすれば
commit 2a08e46f36ed7d10a431adc6fdf227548212902c
Author: snowpool
Date: Fri May 31 21:33:01 2013 +0900

shared start
というように、無事に commit されているのが
確認できます

ここまでは問題ないのですが
ここから共有リポジトリに送ろうとすると
エラーで止まります

git push origin master
を実行すると

To /home/snowpool/ourweb.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '/home/snowpool/ourweb.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.

となり、エラーがおきて先にすすめません

hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
とあるように、
先に git pull するように促されます

この場合、
git push origin master
を実行します

修正箇所が異なっている分には問題があまりないのですが
修正箇所が同じ場合コンフリクトが発生します

このため、修正することが必要になります

今回、 vim index.html でファイルを開くと
以前、コンフリクトの修正をしたときのように

line 1st
line2
line3
line end
<<<<<<< HEAD
share start!
=======
share test
>>>>>>> c11d37315a0378907809998e842de7b1a59ffbde

となっているので、

line 1st
line2
line3
line end
share start!
というように修正し、保存します

あとは、インデックス化とコミットを両方一気に行うので
git commit -am "conflict fixed"

そして再び
git push origin master
を実行すると、無事に実行できます

このように、共有リポジトリの場合
git push
git pull
を多用することになりそうです

あと、Git サーバー - プロトコルがあって
Local
SSH
Git
HTTP/S
といったプロトコルが使えます
それぞれ利点、欠点がありますので
用途により使い分けすることになると思います

プロトコルに関しては
Git サーバー - プロトコル

に詳細がかかれています
スポンサーサイト



テーマ : Linux
ジャンル : コンピュータ

git のリポジトリ内容の共有

git のリポジトリ内容の共有

#21 リポジトリの内容を共有してみよう
http://dotinstall.com/lessons/basic_git/6721
をもとに、
複数ユーザでの内容の共有について学習

今回は、共有リポジトリの内容を
myweb2
というディレクトリの中に作成する

これには
git clone
を使う

git clone ~/ourweb.git/ myweb2
と実行すると

Cloning into 'myweb2'...
done.
となり、
新しく myweb2 というディレクトリが作成され
その中にリポジトリも作成されている

書式としては
git clone 共有リポジトリのURL 新しいディレクトリ
というかんじになる

内容ができているか、確認するには
cd myweb2/
git log
で確認できる

そして、今度は、myweb2 の中でファイルを編集して
それを 共有リポジトリに追加する
vim index.html
でファイルを開いて
line end
と追記して保存

git add .
でインデックス化

git commit -m "line end added"
でリポジトリ登録


git clone したときに、リモート情報も
引き継ぎできているので
git push で共有リポジトリに追加することができる

今回なら
git push origin master
とすれば、URLの指定をせずに、そのまま送ることができる
これは、リモート情報も引き継ぎしているため


とりあえず、ユーザB役での編集などはできたので
今度は
ユーザA役の myweb ディレクトリで操作する
Linux なら端末を
Ctrl + Alt + t で開けるので
新しい端末を開いて
cd myweb/
で移動

共有リポジトリの内容をマージするには
git pull
を使う

でも、違いを理解するために
まずは git log で内容の確認

commit 0180f5a3844aa7df2cb4c231f03df5e61f36efe9
Author: snowpool
Date: Thu May 30 20:51:12 2013 +0900

line3 added
が最新の内容

確認したら、 git pull で内容を共有リポジトリから引っ張ってくる
今回なら
git pull origin master
とする

これで、git log で内容を確認すると

commit b3c348a6f9fa5416831020ad5649fbdf09050acc
Author: snowpool
Date: Fri May 31 20:57:41 2013 +0900

line end added

とでているので、
ユーザB役の myweb2 ディレクトリで編集したものも
しっかりと反映されていることが確認できる


これらのことから、
git clone で共有リポジトリを作成

git push で編集した内容をアップする

git pull で編集された内容をダウンロードして編集する

というような流れで複数の人による共同開発が可能となる

もっとも、複数人数での開発以外にも
git サーバーを構築して
自分の複数マシンでソースを共有することで
外出先でもソースの編集を容易にするという使い方もできるので
git 関連をやっておくと便利だと思う

テーマ : Linux
ジャンル : コンピュータ

git の共有リポジトリの設定

git の共有リポジトリの設定

#19 はじめての共同作業
http://dotinstall.com/lessons/basic_git/6719
を参考に
git での共有リポジトリを作成

これを使い、後々複数人で共同作業できるようにする予定
これを使えば、他の人とソースを共有して開発ができる


共有リポジトリは、本来ならネットに公開して使うもの

.git と名前を付ける

今回は ourweb.git という名前にする

今回は
ユーザAが myweb ディレクトリ
ユーザBが myweb2 ディレクトリで作成している状態

まず、共有ディレクトリにするために
mkdir ourweb.git

ourweb.git というディレクトリを作成する

cd ourweb.git
でディレクトリを移動して
共有リポジトリを作成する

共有リポジトリを作成するには
git init --bare
とする

--bare オプションをつけることで
これにより管理ファイルだけの管理となり
ここでは commit などをしないようになる

とりあえず、共有の設定はできたので
さっきまで作業していたディレクトリへ移動する
cd ../myweb

これでユーザA役のディレクトリに移動したので

#20 共有リポジトリにpushしてみよう
http://dotinstall.com/lessons/basic_git/6720
を参考にすすめていく

まずは、共有のリポジトリを登録するので
別のリポジトリを登録する
git remote
を使う

追加には add をつけるので
git remote add origin ~/ourweb.git
となる

書式としては
git remote add origin gitのパス
となる
git のパスは http:// というようなURLでもOK

git config -l
で状態確認できるので
ここで remote.origin のURLの確認もできます

core.editor=vim
alias.co=checkout
alias.st=status
alias.br=branch
alias.ci=commit
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=/home/snowpool/ourweb.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

が実行結果で
remote.origin.url=/home/snowpool/ourweb.git
がURLとなります

もし、削除したいのなら
git remote rm origin gitのパス
で削除も可能

ここまでで設定ができたので
master ブランチの内容を
共有リポジトリにいれる

これは
git push origin master
とすればできる

成功すると
Counting objects: 20, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (20/20), 1.76 KiB, done.
Total 20 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (20/20), done.
To /home/snowpool/ourweb.git
* [new branch] master -> master
というメッセージがでてくる

転送の書式は
git push origin ブランチ名

テーマ : Linux
ジャンル : コンピュータ

git で短縮名のエイリアスを使う

git で短縮名のエイリアスを使う

#18 エイリアスを使ってみよう
http://dotinstall.com/lessons/basic_git/6718
を参考に
エイリアスについて学習

これは git のコマンドを短縮名でつかうというもの

例えば
git checkout
これを短縮したいなら
git config --global alias.co checkout
とする

これと同様に
status
branch
commit
これらも短縮で使えるように登録しておく

git config --global alias.st status
git config --global alias.br branch
git config --global alias.ci commit

こうしておくことで
bit branch を
git br
で行うことができる

Linux の場合、Tab キーによる補完機能を使えば
ある程度は楽できるけど
このエイリアスを設定することでよりやりやすくできる

設定したエイリアスについては
git config -l
とすることで確認が可能

私の環境の場合だと
core.editor=vim
alias.co=checkout
alias.st=status
alias.br=branch
alias.ci=commit
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
となっています

テーマ : Linux
ジャンル : コンピュータ

git でのタグ

git でのタグ

git をわかりやすくするためのタグについて学習
参考サイトは
#17 タグを使ってみよう
http://dotinstall.com/lessons/basic_git/6717

git のタグは
git commit したときのID

commit cce3862b9c30a544c772e675ccd5f6a98e345022
というような数字の羅列ではわかりにくいので
これをわかりやすくするために
タグを使う

まずは、実践したほうがわかりやすいので
vim index.html
で最後に
line3 を追記して保存

そして
git add .
git commit -m "line3 added"
でリポジトリ作成

これで git log で確認すると

commit 0180f5a3844aa7df2cb4c231f03df5e61f36efe9
Author: snowpool
Date: Thu May 30 20:51:12 2013 +0900

line3 added

が追加されているのを確認できる

今回は、まずここへ version 1.0 というタグをつける

直近の commit に対してタグを付けるには
git tag v1.0
というようにする

書式は
git tag タグ名

また
git tag
とすれば、タグの一覧をみることができる

また、タグを付けることで
タグからcommit 内容をみることも可能

git show v1.0
というように
git show タグ名
とすれば

commit 0180f5a3844aa7df2cb4c231f03df5e61f36efe9
Author: snowpool
Date: Thu May 30 20:51:12 2013 +0900

line3 added

diff --git a/index.html b/index.html
index fc3bbf4..705cd1f 100644
--- a/index.html
+++ b/index.html
@@ -1,2 +1,3 @@
line 1st
line2
+line3
というように、タグをつけた commit の内容をみることができる

タグ名は git tag で確認できる

git tag タグ名は、直近の commit だけで
もっと前のものにもタグをつけたいのなら
git tag タグ名 commitのID
とする
commit のIDは、全部ではなく
最初から7行ぐらいまででOK

例えば
commit 0180f5a3844aa7df2cb4c231f03df5e61f36efe9
のIDのところに v0.9 としたいのなら

git tag v0.9 0180f5a3844aa7

というようにする
これで、git tag
とすれば
v0.9
v1.0
となる

あとかた追加したタグでも
git show v0.9
とすることで

commit 0180f5a3844aa7df2cb4c231f03df5e61f36efe9
Author: snowpool
Date: Thu May 30 20:51:12 2013 +0900

line3 added

diff --git a/index.html b/index.html
index fc3bbf4..705cd1f 100644
--- a/index.html
+++ b/index.html
@@ -1,2 +1,3 @@
line 1st
line2
+line3

というように、問題なく追加できる

また、タグを削除したいときには
git tag -d v0.9
というように
git tag -d タグ名
とすれば消す事ができる

成功すると
Deleted tag 'v0.9' (was 0180f5a)
というようなメッセージがでる


消えているか確認するには
git tag
で一覧がでるので、ここからなくなっていれば消去成功

テーマ : Linux
ジャンル : コンピュータ

最新記事
検索フォーム
GREEハコニワ攻略サイト
リンク
カテゴリ
月別アーカイブ
フリーエリア
最新記事
FXプライムレート
最新コメント
最新トラックバック