普段使ってて便利だと思った Git コマンドのオプション
log
# 表示数を指定
$ git log -n x(x は出力したい数)
# コミット履歴を 1 行で表示
$ git log --oneline
# コミット履歴の情報を少なくして表示
$ git log --pretty=short
# コミットログを任意のフォーマットで出力
## %h : ハッシュ(省略形)
## %H : ハッシュ
## %ai : 日付
## %an : Author 名
## %s : コミットメッセージ概要
$ git log --format=format:'%h %ai %an %s'
# %C で色の変更も可能 (この辺は alias 設定しておくと便利)
$ git log --format=format:'%C(red)%h %C(yellow)[%ai] %C(blue)<%an> %C(green)%s %C(yellow)(%ar)'
add
# 変更したファイルをすべて追加(新規ファイルは含まれない)
$ git add -u
# 1 つのファイルの変更点を部分的に追加できる
$ git add -p
# 変更ファイルを強制的にコミットする
# .gitignore に登録されているファイルを登録したいときに使える
$ git add -f
commit
# 変更ファイルの追加とコミットを同時に行う
$ git commit -a
# 直前のコミットをやりなおす
# コミットメッセージの修正などに便利
$ git commit --amend
diff
# HEAD とインデックスの差分表示 (stage のファイル差分を表示)
$ git diff --cached
# HEAD とワーキングツリーの差分を取るときは下記
$ git diff HEAD
# 空白文字を無視して比較
$ git diff -w
# 行ではなく単語単位で差分を表示
$ git diff --color-words
branch
# ブランチ一覧とその HEAD 情報を取得
$ git branch -v
# ブランチ名の変更
$ git branch -m
grep
# 行番号を表示
$ git grep -n
# 大文字小文字の区別をしない
$ git grep -i
stripspace
# trailing space の削除
$ git stripspace < TargetFile.txt > Temp.txt
$ mv Temp.txt TargetFile.txt