miyohideの日記

技術的なメモなどを記しています

2019年2月27日

どんどん賢くなっていく。

リモートで消したブランチをローカルでも消す

GitのTip。GitHubとか使って開発しているとき、Pull Requestがマージされてブランチも消したらローカルのブランチも消したい。この作業、これまでは一つ一つブランチを調べてローカルでコマンド打って消していたんですが、そんなことしなくても良かった。

$ git fetch --prune

でOK。

今まで手作業でしていたことは何だったんだ。

2019年2月22日(金)

今日は打ち合わせもないし、じっくりとドキュメントを読んだりコード書いたりするぞ!って思っていたのに色々とトラブルが...

git checkout ours/theirs

今までGitでconflictした場合ちまちまと手で直していたんですが、「自分のもので上書きしたい」とか「リモートに上がっているもので上書きしたい」という場合にはgit checkout --oursgit checkout --theirsが使えるよということを知りました。きっかけは以下のQiitaの記事。

qiita.com

自分でもやってみました。

まずは、準備。2つのブランチで同じファイルを編集・コミットしておく。

$ mkdir git_checkout_test
$ cd git_checkout_test/
$ git init
Initialized empty Git repository in /Users/miyohide/work/tmp/git_checkout_test/.git/
$ git commit --allow-empty -m "initial commit"
[master (root-commit) f46fa43] initial commit
$ touch file
$ git add .
$ git commit -m "add file"
[master 1b32c4a] add file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file
$ git checkout -b a_branch
Switched to a new branch 'a_branch'
$ echo "a branch 1" >> file
$ git commit -a -m "a branch commit 1"
[a_branch aea8c0c] a branch commit 1
 1 file changed, 1 insertion(+)
$ echo "a branch 2" >> file
$ git commit -a -m "a branch commit 2"
[a_branch 76fb789] a branch commit 2
 1 file changed, 1 insertion(+)
$ echo "a branch 3" >> file
$ git commit -a -m "a branch commit 3"
[a_branch 1321b44] a branch commit 3
 1 file changed, 1 insertion(+)
$git checkout -b b_branch master
Switched to a new branch 'b_branch'
$ echo "b branch 1" >> file
$ git commit -a -m "b branch commit 1"
[b_branch ec7500b] b branch commit 1
 1 file changed, 1 insertion(+)
$ echo "b branch 2" >> file
$ git commit -a -m "b branch commit 2"
[b_branch 7242dbc] b branch commit 2
 1 file changed, 1 insertion(+)
$ echo "b branch 3" >> file
$ git commit -a -m "b branch commit 3"
[b_branch 96e1d8a] b branch commit 3
 1 file changed, 1 insertion(+)
$ git checkout master
Switched to branch 'master'
$ git log --graph --all --format="%x09%x09%h %d %s"
*               96e1d8a  (b_branch) b branch commit 3
*               7242dbc  b branch commit 2
*               ec7500b  b branch commit 1
| *             1321b44  (a_branch) a branch commit 3
| *             76fb789  a branch commit 2
| *             aea8c0c  a branch commit 1
|/
*               1b32c4a  (HEAD -> master) add file
*               f46fa43  initial commit
$

ここでa_branchb_branchのものをmergeしようとするとconflictを起こします。

$ git checkout a_branch
Switched to branch 'a_branch'
$ git merge b_branch
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
$ cat file
<<<<<<< HEAD
a branch 1
a branch 2
a branch 3
=======
b branch 1
b branch 2
b branch 3
>>>>>>> b_branch
$

ここで今回学んだこと。git checkout --oursを使うと、自分たちのもの、つまりa_branchのものが採用されます。

$ git checkout --ours file
$ cat file
a branch 1
a branch 2
a branch 3
$

一方、git checkout --theirsを使うと、他方の、つまりb_branchのものが採用されます。

$ git checkout --theirs file
$ cat file
b branch 1
b branch 2
b branch 3
$

2019年2月21日(木)

地味にTypoが多くなった気がする。

めっちゃハマったこと

今日めっちゃはまったこと。

irb(main):009:0> e = Time.parse('2019-04-1 0:0:0')
=> 2019-04-01 00:00:00 +0900
irb(main):010:0> s = Time.parse('2019-03-1 0:0:0')
=> 2019-03-01 00:00:00 +0900
irb(main):011:0> s + 1.month == e
=> true
irb(main):012:0>

ここまでは普通のことなんだけれども...

irb(main):012:0> (e - s) == 1.month
=> false
irb(main):013:0>

え?なんで?

どうもe-sのときの右辺にある1.monthは30日で計算しているみたい。一方でs + 1.monthのときの1.monthは単に月の数字を1つ足しているように見える。

明日ちゃんとソース読んでおこう。

2019年2月18日(月)

出勤すると何故か仕事が降って湧いてくるのはなんでだろう。

私は左派

ネタ記事だけれども。

www.gizmodo.jp

私はmacでもWindowsでも左側にDockやタスクバーを置きます。なんだかんだ、これが自分にとって一番使いやすい。

2019年2月17日(日)

忙しさにかまけてやる気が迷子な気がする。

Go言語のお勉強

Go言語のお勉強として、いろいろとコードを読んでいるんだけれども、以下のサイトに書かれているコードを読んではて?と思った。

shogo82148.github.io

func newHandler() http.Handler {
    mux := http.NewServeMux()
    mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "from pid %d.\n", os.Getpid())
    })
    return mux
}

戻り値としてhttp.Handlerを指定しているのに、returnとしてhttp.NewServeMux()が返しているServeMuxを返すことができるんだろう...。

そんなことをウンウン悩んでいたら、以下のようなアドバイスを頂いた。鍋谷さん、ありがとうございます。

なるほど。確かにhttp.Handlerの定義を見ると、

type Handler interface {
        ServeHTTP(ResponseWriter, *Request)
}

とある。

golang.org

一方で、ServeMux型はServeHTTPを実装している。

golang.org

なるほど。Go言語、全然理解できてなかった。

2019年2月12日(火)

今日はやたらと電車が混んでいたイメージ。3連休初日で出勤する人が多かったのかな。

Rspec HTML Reports

どこからこれを見つけたのかあまり覚えていないけれども、最近rspec_html_reporterってものを見つけました。

github.com

検索したらメルカリさんのブログにヒット。メルカリさんはAndroidのE2Eテストレポートとして使用しているようです。

tech.mercari.com