自分用 Git コマンドまとめ / Git command note to myself
2022-09-21: v0.1, First edition
パッチ関連 / Patch
- メール形式単一パッチ作成 / Single patch in the mail format
- git format-patch commit0 > hoge.patch
- メール形式複数パッチ作成 / Two or more patches in the mail format
- git format-patch commit1..commit2 -o direcitory
履歴を見る / History
- ツリーで見る / log in tree
- git log --oneline --decorate=full --graph --branches --tags --remotes
- 日付指定 / Specify the date (range)
- git log --since=<date> --after=<date> --until<date> --before=<date>
- パターンで検索 / Search by pattern
- git log --grep="<pattern>"
- コミットメッセージから検索 / Search from the commit message
- git log -p -S 'function hoge'
- 逆順 / Reverse order
- git log --reverse --decorate
クローンする / Clone
- Shallow clone
- git clone --depth 1
- クローンするときにディレクトリ名を指定 / Specify the directory name
- git clone url directory-name
スタッシュ / Stash
- 一部だけstashに入れる / Push not all the part into the stash
- git stash -p
zipに固める / Archive to zip
- 展開時にディレクトリが作成されるようにする / Archive with single root directory
- git archive HEAD --prefix=<dir>/ -- output../hoge.zip
- Note: '/' is required at the last of the <dir> for prefix
- git archive HEAD --prefix=<dir>/ -- output../hoge.zip
ブランチ操作 / Branch
- ブランチの削除 / Delete the branch
- git branch --delete branch-name
- git branch -d branch-name
- ブランチのリネーム / Rename the branch
- git branch --move old-branch-name new-branch-name
- git branch -m old-branch-name new-branch-name