- 必須
git config --global user.name "Username"
git config --global user.email "yourname@subdomain.tld"
- 任意: gitの出力をカラー表示にする。
git config --global color.ui auto
- 任意:
git push
実行時にupstreamが設定されていなくても、現在のローカルのブランチ名と同じブランチ名でリモートにpushする設定。
git config --global push.default current
- 任意: mergeの時にデフォルトをno-ffとする。
git config --global merge.ff false
- 任意: pull時のmergeをrebaseにする。
git config --global branch.autosetuprebase always
- 設定確認
git config --list
git mv <oldfilename> <newfilename>
git log --oneline --decorate --graph --branches --tags --remotes
- ワーキングディレクトリの変更内容は残す。
git reset --soft
git reset --soft HEAD^
- ワーキングディレクトリの変更内容も消す。
git reset --hard
- 通常のcommitの場合
git revert <commitのSHA1>
- merge commitの場合
git revert -m 1 <merge commitのSHA1>
git branch -m <oldbranch> <newbranch>
git remote update origin --prune
git checkout -b <new-branch> origin/<new-branch>
- はじめにローカルのbranchを削除する。
git branch -d <branch-name>
- リモートのbranchを削除する。
git push origin :<branch-name>
git diff <branch1> <branch2>
- 差分ファイルのみの出力
git diff --name-only <branch1> <branch2>
git cherry-pick <commit-id>
- 変更履歴を保存する。
git stash save "comments"
- stashしたログを出力。
git stash list
- 変更履歴を戻す。
git stash pop stash@{0}
- 変更履歴の一部削除。
git stash drop stash@{0}
- 変更履歴をすべて削除。
git stash clear
- リモートのtagの情報を取得する。
git remote update
- tagの一覧を確認。
git tag
- tagの詳細を確認。
git show <tag名>
- tagのブランチを作成してチェックアウトする。
git checkout -b <tag名> refs/tags/<tag名>
- 現在のブランチを優先する。
git checkout --ours <filename>
- マージしたブランチの方を優先させる。
git checkout --theirs <filename>
- 最後にコミット。
git commit