Gitの初心者の方が覚えておくと便利かなと思うコマンド一覧です。
直前のcommitに追加で変更を加えたい
一つ前のcommitに現在の変更を加える
$ git commit --amend
commitしたけど名前が気に入らない
一つ前のcommitの名前を変更する
$ git commit --amend -m "commit name"
1つ以上前のcommitをまとめたい
複数のcommitをまとめる
$ git rebase -i HEAD ~ [commit id]
commit間のdiffをみたい
commit間の変更を見る
$ git diff [commit id] [commit id]
remoteとのdiffをみたい
remoteのbranchとの差を見る
$ git diff HEAD [remote branch]
作業途中だけどremoteからpullしたい
# stashで変更を退避
$ git stash
# 変更がすべて退避されたので、pull
$ git pull [remote branch]
# 退避した変更を適応
$ git stash apply [stash id]
remoteからbranchをcheckoutしたい
$ git checkout -b [branch name] [remote branch]
変更をすべて消し去りたい
一つ前のcommitの状態にもどす
$ git reset --hard HEAD
ある時点のcommitまで戻したい
指定した時点までcommitを戻す
$ git reset [commit id]
commitを消してしまった時
# commitログを確認
$ git reflog
# commitを戻す
$ git reset --hard [commit id]