Skip to content

Instantly share code, notes, and snippets.

@hachi-eiji
Created December 21, 2014 07:29
Show Gist options
  • Save hachi-eiji/ff6a8e1e2f49a8c54019 to your computer and use it in GitHub Desktop.
Save hachi-eiji/ff6a8e1e2f49a8c54019 to your computer and use it in GitHub Desktop.

自分のGitルール

ローカルリポジトリでの開発

  1. cloneする
  2. 大きな修正になりそうなのはbranchを作成する
  3. branchで普通に開発する
  • コミット時は2行書く
  1. branchにpushする
  2. 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

mergeとrebaseの違いは毎回忘れるのでこちらを参考 http://powerful-code.com/blog/2012/11/merge-or-rebase/

リモートリポジトリにpushする

  1. ログをまとめる
  2. 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コマンドを実行する(?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment