🐥
よく使う Git コマンドまとめ
よく使う Git コマンドまとめ
Git を教える機会があったので、まとめておく。
- セットアップ
- git init
- git config --local user.name
<user name>
- git config --local user.email
<user email>
- git branch -M
<branch name>
- git remote add origin
<url>
- 現在参照しているブランチ名を変更
- git branch -m
<new branch name>
- git branch -m
- 新規ブランチを任意のブランチをベースにして作成
- git checkout -b
<new branch name>
<base branch name>
- git checkout -b
- ブランチを強制的に変更(checkout)
- git checkout -f
<branch name>
- git checkout -f
- インデックスに記録されているファイルをインデックスから解除
- git restore --staged
<file name>
- git restore --staged
- インデックスに記録されているファイルとリモートトラッキングブランチとの差分
- git diff --staged origin/
<branch name>
- git diff --staged origin/
- プルリクエストで発生したコンフリクトを修正
- merge
- git fetch
- git merge
<branch name>
- git add
<file name>
- git merge --continue
- rebase
- git fetch
- git rebase origin/
<branch name>
- git add
<file name>
- git rebase --continue
- pull
- rebase
- git pull --rebase origin
<branch name>
- git add
<file name>
- git rebase --continue
- git pull --rebase origin
- merge
- git pull origin
<branch name>
- git add
<file name>
- git merge --continue
- git pull origin
- rebase
- merge
- インデックスに記録されている変更を直前のコミットに混ぜる
- git commit --amend
- 前にいたブランチに戻る
- git checkout -
- ファイルの行単位で最終変更がどのコミットで行われたのか確認
- git blame
<file name>
- git blame
- 直前のコミットで変更したファイルの内容を見る
- git show
- コミット対象外のファイルを削除
- git clean -f
- option
- f 強制
- d ディレクトリも含む
- n 空実行
- option
- git clean -f
- ワーキングツリーの変更を元に戻す
- git checkout .
- ワーキングツリーとインデックスの変更を元に戻す
- git checkout -f
- リベースをキャンセル
- git rebase --abort
- cherry-pick をキャンセル
- git cherry-pick --abort
- マージをキャンセル
- git merge --abort
- 特定のファイルをインデックスに追加
- git add
<file name>
- git add
- HEAD の状態をインデックスに戻す
- git reset --mixed HEAD^
- ワーキングツリーとインデックスの状態を HEAD に戻す
- git reset --hard HEAD
- 特定のファイルのブロックだけインデックスに追加
- git add -p
<file name>
- git add -p
- ワーキングツリーとインデックスの差分をインデックスに追加
- git add -u
- インデックスと HEAD の差分を表示
- git diff --staged
- 強制的に push
- git push -f origin
<branch name>
- git push -f origin
- リモートブランチの更新を取り込んで特定のブランチをベースにリベース
- git pull --rebase origin
<remote branch name>
- git pull --rebase origin
- HEAD のコミットメッセージを変更
- git commit --amend
- Git の操作履歴を閲覧
- git reflog
- 前のブランチに強制的にチェックアウト
- git checkout - -f
- ワーキングツリーとインデックスの変更を直前のコミットに混ぜる
- git commit -a --amend
- サイズの大きなファイルをプッシュ(100MB 超)
- Git LFS を使用
- brew install git-lfs
- git lfs install --local
- 管理ファイル設定
- git lfs track
<large file path>
- git add .gitattributes
- git add
<large file path>
- git lfs track
- git commit
- git push origin
<branch>
- Git LFS を使用
Discussion