gitの小ネタ

git使ってて気になったことのまとめ。
自分のための備忘録

文字化け

git diffなどで文字化けするときは以下の設定を行えばいいようです。

% git config --global core.pager "lv -c"
http://d.hatena.ne.jp/takihiro/20100523/1274567613

git pullができない

git pullしようとして以下のメッセージが出る場合。

Enter passphrase for key '/home/**/.ssh/id_rsa': 
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

    [branch "master"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

これは

これはgit側の話で、cloneしたときはclone元からpullできるように設定されるが、initしてpushした場合は当然そう言う参照関係にはならないよってことですね。

http://d.hatena.ne.jp/hiratara/20090110/1231554423

とのことらしい。

ので、

% git config branch.master.merge refs/heads/master
% git config branch.master.remote origin
http://d.hatena.ne.jp/sugyan/20091002/1254436981

とすればよいっぽい。
#表示されてるメッセージが参照先のと違うけど、まぁ動いたのでちゃんと調べるのは後回し・・・

git logのグラフ表示

git logにはグラフ表示できるオプションがあるみたいです。
が、毎回打つのが面倒なのでエイリアスを登録しようという話です。

詳細はリンク先を参照。
http://yumewaza.yumemi.co.jp/2010/07/git.html

pushしたコミットの取り消し

以下のコマンドでoriginのmasterブランチをそのひとつ前のコミットに戻す

% git push -f origin HEAD^:master

参考:
http://d.hatena.ne.jp/n7shi/20100204/1265382280
http://d.hatena.ne.jp/shunsuk/20101202/1291278345

commit時のエディタエラー

$ git config --global core.editor "/usr/bin/vim"

export GIT_EDITOR="/hoge/hoge"
git commitでエディタ編集後エラーとなる場合 - MPD~モチドレ