ローカルリポジトリでの開発
- cloneする
- 大きな修正になりそうなのはbranchを作成する
- branchで普通に開発する
- コミット時は2行書く
- branchにpushする
- rebaseする
git clone <URL>
git checkout -b <branch_name>
git commit -m 'subject' -m 'body'
git push origin <branch_name>
git rebase master
git checkout master
git rebase <branch_name>
他のリポジトリからforkしたときは、masterに取り込む
pull オプションに--rebaseをすることで、コミット内容がマスターからの変更分に置き換わるため、プルリクエストの内容が変更した内容だけになる
git remote add upstream <URL>
git fetch upstream
# mergeではなくてrebase
git rebase upstream/master
ただし、一度pushした後にupstream/masterの内容を取り込む際はmergeを使うこと。rebaseは内容は同じだが、1つ前のコミットが異なるためリビジョンは別物になる。
mergeとrebaseの違いは毎回忘れるのでこちらを参考
http://powerful-code.com/blog/2012/11/merge-or-rebase/
http://blog.inouetakuya.info/entry/20130602/1370173582
リモートリポジトリにpushする
- ログをまとめる
- pushする
pull requestするとゴミログが出てこないはずだからこちらのほうが、ログが綺麗になると思う。
→ fork元が更新されてた時にはどのような挙動になるのか?
git rebase -i HEAD~2
git commit --amend
git rebase --continue
git push origin master
pick 9a54fd4 commitの説明を追加
pick 0d4a808 pullの説明を追加
↓
e 9a54fd4 commitの説明を追加
f 0d4a808 pullの説明を追加
# Rebase 326fc9f..0d4a808 onto d286baa
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
p,pick = commitをそのまま使う
r,reword = commit messageだけ編集する
e,edit = commitをまるごと編集する
s,squash = reflogを残したままcommitを直前のcommitに統合し、統合後のメッセージを編集する
f,fixup = reflogを残さず、commitを直前のcommitに統合する
x,exec = shellコマンドを実行する(?)