分散バージョン管理システムGit入門Beginner's Guide(3/3 ページ)

» 2009年02月09日 08時00分 公開
[松島浩道,SourceForge.JP Magazine]
SourceForge.JP Magazine
前のページへ 1|2|3       

リモートリポジトリから変更点を取得する

 リモートリポジトリに加えられた変更点を取得し、それらをローカルリポジトリに適用するには「git pull」コマンドを利用する。次の実行例は、ユーザー名「hoge」で「git.sourceforge.jp:/gitroot/test /test.git」というリポジトリから変更点を取得する例だ。


$ git pull hoge@git.sourceforge.jp:/gitroot/test/test.git
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
From hoge@git.sourceforge.jp:/gitroot/test/test.git
 * branch            HEAD       -> FETCH_HEAD
Updating fd311c5..cf6c47c
Fast forward
 macosx/HBPreferencesTransFormer.h |   16 ++++++++++++++++
 macosx/HBPreferencesTransFormer.m |   14 ++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
 create mode 100644 macosx/HBPreferencesTransFormer.h
 create mode 100644 macosx/HBPreferencesTransFormer.m

 このとき、もし競合が発生した場合は次のようにその旨が表示される。


$ git pull hoge@git.sourceforge.jp:/gitroot/test/test
Auto-merged markup.pl
CONFLICT (content): Merge conflict in markup.pl
Automatic merge failed; fix conflicts and then commit the result.

 競合が発生したファイル(前記の例ではmarkup.pl)の競合が発生した位置には次のようなマーカーが挿入され、どのように競合が起こっているかが分かるようになっている。


sub ulist {
    if( $l =~ m/^☆(リスト.*)$/ ) {
      $cap = $1;
    }
<<<<<<< HEAD:markup.pl
    print "<ul>\n";
    while( $l =~ m/^・/ ) {
      $l =~ s/^・(.*)$/<li>$1<\/li>/;
      print "foo:$l\n";
      $l = <>;
=======
    print "<p><b>$cap</b></p>\n";
    print list_start( $cap );
    while( $l = <> ) {
>>>>>>> e74597cbfdb9995e540ca9e8c8a6e79705e2889c:markup.pl
      chomp $l;
      $l =~ s/&/&amp;/g;
      $l =~ s/</&lt;/g;
      $l =~ s/>/&gt;/g;
}

 この中で、「<<<<<<< HEAD:markup.pl」から「=======」までがマスターリポジトリ内のソースコード、「=======」から「≪>>>& gt;>>> e74597cbfdb9995e540ca9e8c8a6e79705e2889c:markup.pl」までがローカルリポジトリ内にあったソースコードだ。競合部分を確認・編集し、競合を解消して「git commit」コマンドでコミットを実行すれば、git pushでpushが行えるようになる。

ヘルプの使い方

 最後に、オンラインマニュアルの使い方について紹介しておこう。Gitのオンラインマニュアルは、UNIXの伝統に従いmanページで提供されており、Gitの概要については「man git」で確認できる。


$ man git
NAME git - the stupid content tracker SYNOPSIS git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS] ...

 また、「git init」や「git commit」といったサブコマンドの使い方は、例えば「man git-init」や「man git-commit」のように、ハイフンでサブコマンドを繋いでmanコマンドを実行することで閲覧できる。


$ man git-init
GIT-INIT(1)                             Git Manual                            GIT-INIT(1)
NAME git-init - Create an empty git repository or reinitialize an existing one
SYNOPSIS git init [-q | --quiet] [--bare] [--template=] [--shared[=]] ...

 そのほか、「man gittutorial」でチュートリアルを読むこともできる。現時点でマニュアルは英語でしか提供されていないが、これに目を通しておけば基本的なGitの使い方をマスターできるだろう。

新しいことをはじめる前には「Beginner's Guide」で知識を得てみませんか?


前のページへ 1|2|3       

Copyright © 2010 OSDN Corporation, All Rights Reserved.

注目のテーマ