Skip to content

Instantly share code, notes, and snippets.

@suvene
Created February 11, 2013 09:43
Show Gist options
  • Save suvene/4753530 to your computer and use it in GitHub Desktop.
Save suvene/4753530 to your computer and use it in GitHub Desktop.
git rebaseについて
git pull について
http://dxd8.com/archives/218/
------
O-Show 2011-04-08 05:20
こんにちは。
git config branch.ブランチ名.mergeoptions “–no-ff”
で常にファストフォワードではないマージを行うことについて一つ。
git pull はデフォルトでは「git fetch してから git merge」 と同じなので、
変更を取ってきたいだけの git pull でもマージコミットが作られます。
(–no-ffのmergeにしてなくても、他人と一緒に作業しているブランチが
 すぐマージコミットまみれになってしまうのを見たことがあるかもしれません)
もしこれが嫌という場合、git pull を git pull –rebase と打てば、
git pull の効果が「git fetch してから git rebase
(変更を一つずつ再適用する)」になります。
git pull と打つだけで常に git pull –rebase とするようにするには、
$ git config branch.ブランチ名.rebase true
これで、該当ブランチで git pull をするとそれが git pull –rebase になります。
また、全てのブランチで rebase するようにするには
$ git config branch.autosetuprebase always
です。
意図的にマージコミットを増やしたい場合のための –no-ff、
マージコミットを増やしたくない時のための git pull –rebase という感じです。
git pull –rebase
は『入門Git』でも『実用Git』でもほとんど触れられていないので、
本だけだと案外知らない方もいるかもしれません。
海外では「git pullではなくどんな時もgit pull
–rebaseしろ」という議論もあるようです。
http://yehudakatz.com/2010/05/13/common-git-workflows/
本題外のことをいきなり長々とすみませんでした。
自分が元記事を翻訳してからずっと気になってた点だったもので…。
------
Phize 2011-04-08 22:07
こんにちは。
O-Showさんの翻訳をきっかけにこのモデルを知り、日本語訳はモデルの理解に大変参考にさせていただきました。そして、補足ありがとうございます
複数人が関わる場合などには branch.ブランチ名.mergeoptions “–no-ff”
で設定してしまうと困るケースは多いかもしれませんね。
もっとも毎度ブランチごとに設定するよりは、エイリアスを使うかその都度指定するのが確実な気はします。
元記事のコメント欄を確認してみたところ、同様のつっこみもあるようです。
Bobby Eickhoff 6 months ago
“I would like to politely disagree with you on one statement:
“Unfortunately, I have not found a way to make –no-ff the default behaviour
of git merge yet, but it really should be.” I think you make an excellent
case that there are times when –no-ff makes the most sense. However, there
are times when it would make no sense. Consider that if –no-ff were the
default for git merge, then every invocation of git pull could introduce a
(completely unnecessary) commit which would only clutter up the commit graph.
(Note also that the amount of such clutter will grow linearly with the number
of developers and the frequency with which they pull.)””
git pull –rebase
は、本では本当に軽く存在が触れられている程度ですが、設定次第で全ブランチでrebaseできるのならかなり便利そうですね。
これは是非使っていきたいので、紹介してくださったリンク先と合わせて確認してみます。
Gitを使いこなすにはまだまだほど遠いですが、今後ともよろしくお願いします。
------
O-Show 2011-04-08 23:58
元記事のコメントまでは追っていませんでした、
情報ありがとうございます!
仰るとおりエイリアスかその都度指定するのがいいという気がします。
後はうまく出来るかわかりませんが、コミットフックとかを使って
–no-ffしてない時は警告を出すみたいなことぐらいでしょうか
(merge後にやっぱり–no-ffが必要だったと思ったら、その場ですぐresetしてやり直し)。
git pull –rebaseは、このモデルに関わらず必要となると思いますので、
是非もっとみんなに知ってほしいです。
自分もGitを使いこなすにはまだまだですので、勉強して行きたいと思います!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment