Hatena::ブログ(Diary)

u16suzuの日記

2012-02-21

git コミットをまとめる

| 15:19

git コミットをまとめるには以下を実行する。

エディタが開くので pick を squash にする。

$ git rebase -i HEAD~3

すでに push した場合は、以下で強制的にプッシュできる。

一人で使っている場合はこれでいい。

$ git push origin -f 

2012-02-04

nginxを停止しても再起動してしまう。

21:52

Macでnginxをインストールし起動後、kill -s quit しても、master, worker プロセスが再起動してしまう。

ググったら情報が見つかった。

コンフィグファイル /usr/local/etc/nginx/nginx.conf に以下の内容を追加

daemon off;

そして、以下のコマンドで終了。

# sudo nginx -s quit

参考

http://serverfault.com/questions/141975/how-to-stop-nginx-on-mac-os-10-6-3

2012-01-30

Procオブジェクト生成方法の3種盛り合わせ

| 09:23

メタプロより。

inc = Proc.new { |x| x+1}
p inc.class
p inc.call(33)

dec = lambda { |x| x-1}
p dec.class
p dec.call(33)

def fuga(&the_proc)
  the_proc
end

mul = fuga{|x, y| x*y}
p mul.class
p mul.call(4,5)

結果

Proc
34
Proc
32
Proc
20

3番目の方法は知らなかった。

yieldメモ

09:05

&を使うことでメソッドにブロックを渡すことができる。

def hoge(a, b, &op)
  yield a, b
end

p hoge(3,4){|x,y| x*y}

2012-01-26

git submodule の使い方まとめ

| 21:24

git submodule は、本体ソース内から、別のリポジトリを参照する場合に使用する。

git submodule show上と同じ
status サブモジュール一覧を表示する。プレフィックスの意味 - : 未初期化, + : インデックスSHA-1と合っていない, U:コンフリクト発生
add サブモジュールを追加する。その後commit をする必要がある。
init .gitmoduleの情報(名前とレポジトリurl)を .git/config に書き出す
update .git/config の情報を元にsubmoduleをクローンする

git submodule init してから、git submodule updateするのと、git submodule update --init は同じ。

git submodule init で追加される情報は以下のとおり

[submodule "cap_test"]
        url = git@github.com:u16suzu/cap_test.git
git submodule init のヘルプ和訳

Initialize the submodules, i.e. register each submodule name and url found in .gitmodules into .git/config. The key used in .git/config is submodule.$name.url. This command does not alter existing information in .git/config. You can then customize the submodule clone URLs in .git/config for your local setup and proceed to git submodule update; you can also just use git submodule update --init without the explicit init step if you do not intend to customize any submodule locations.

git commit init コマンドはサブモジュール初期化する。つまり、.gitmodules にあるサブモジュールの名前とurlを .git/config に書きだす。 .git/config で使用されるキーは submodule.$name.url である。このコマンドは .git/config の既存のデータを書き換えない。したがって、.git/config にあるURLはローカルのものを指定でき、git submodule update することができる。どのサブモジュールのパスも変更しないならば、 git submodule update --init を使うことで、git submodule init を省略できるよ。

サブモジュールを編集する

サブモジュールで参照した先のファイルを編集した場合は参照元のcommitも行う必要がある。これをしないと、どのコミットを参照しているかわからなくなるらしい。もしくは、submodule の本体レポジトリでコミット&pushし、参照元でpullする。最初は後者の方をやってたけど、大分面倒くさかったので前者に変えた。

前者の場合に、参照元の更新を行わないと、git submodule status のプリフィックス + がでる。

git submodule update するか、上の方法で解決する。

サブモジュールの削除を行うコマンドはない。以下削除の手順。
.gitmodules, .git/config から該当する行を削除後
git rm --cached path/to/hoge
git commit -m "Del: delete submodule"