Git使いになろう:設定あれこれ(1:ページャー)

ここまで、Gitのログを表示するときに –no-pager というオプションを付けていましたが、これはページャーを使わないという指定です。Gitはlogやdiffなどを出力するときにデフォルトでlessを使うようになっています。設定により使うページャーを好みのものに変えたり、ページャーを使わないようにすることができます。

ページャーをmoreに変えるには

$ git config --global core.pager 'more'

とします。

ページャーを使わないように変えるには空文字列を指定すればよいので

$ git config --global core.pager ''

とします。

Git使いになろう:ひとりで使う(7:以前のある時点まで戻す)

ここまでで一つ前のコミットまで戻す方法を紹介しましたが、以前のある時点まで一気に戻す方法もあります。

$ git --no-pager log
commit 8a044cddf697531e560077c05f2939609607ffb1
Author: tomohiro <tomohiro@example.com>
Date:   Thu Mar 10 18:09:04 2016 +0900

    add description

commit ee8831f07fcd5007816ef6e75682b826659a79cd
Author: tomohiro <tomohiro@example.com>
Date:   Fri Jan 1 20:51:25 2016 +0900

    add URL
    
    add the URL of the Ragtimeblues

commit ab374c5f64e3de33b079b9e013ac2cec7830935d
Author: tomohiro <tomohiro@example.com>
Date:   Fri Jan 1 16:57:09 2016 +0900

    first commit

という状態のときに、二つ前のコミットまで一気に戻すには、コミットハッシュ値を指定してgit resetを実行します。コミットハッシュ値とはログメッセージ中のcommitに続く文字列です。上記の例だとab374c5f64e3de33b079b9e013ac2cec7830935dになりますが、一意に特定できればよいので通常は先頭の7文字程度を指定します。

$ git reset --hard ab374c5
HEAD is now at ab374c5 first commit
$ git status
On branch master
nothing to commit, working directory clean
$ git --no-pager log
commit ab374c5f64e3de33b079b9e013ac2cec7830935d
Author: tomohiro <tomohiro@example.com>
Date:   Fri Jan 1 16:57:09 2016 +0900

    first commit

と、一気にab374c5のコミットまで戻せました。