😸

# Gitコマンドチートシート

2024/06/04に公開

設定

コマンド 説明
git config --global user.name "Your Name" ユーザー名を設定
git config --global user.email "your@email.com" メールアドレスを設定

リポジトリ

コマンド 説明
git init 新しいリポジトリを初期化
git clone <url> 既存のリポジトリをクローン

変更の記録

コマンド 説明
git add <file> ファイルをステージングエリアに追加
git add . 全ての変更をステージングエリアに追加
git commit -m "Message" 変更をコミット
git status 現在の状態を確認

ブランチ操作

コマンド 説明
git branch ブランチを一覧表示
git branch <branch> 新しいブランチを作成
git checkout <branch> ブランチを切り替え
git merge <branch> 現在のブランチにマージ
git branch -d <branch> ブランチを削除
git branch -m <old> <new> ブランチ名を変更
git fetch リモートリポジトリの変更を取得
git checkout -b <branch> 新しいブランチを作成し、そのブランチに切り替え
git branch --merged 現在のブランチにマージ済みのブランチを一覧表示
git branch --no-merged 現在のブランチにマージされていないブランチを一覧表示

リモートリポジトリ

コマンド 説明
git remote add <name> <url> リモートリポジトリを追加
git push -u <remote> <branch> 変更をリモートリポジトリにプッシュ
git pull <remote> <branch> リモートリポジトリから変更をプル
git remote -v リモートリポジトリの一覧を表示
git remote rm <remote> リモートリポジトリを削除
git remote rename <old> <new> リモートリポジトリの名前を変更
git remote set-url <remote> <url> リモートリポジトリのURLを変更
git push --tags タグをリモートリポジトリにプッシュ

変更履歴

コマンド 説明
git log コミット履歴を表示
git diff 変更内容を比較
git log --graph コミット履歴をグラフ形式で表示
git blame <file> ファイルの各行の最終変更情報を表示
git log --oneline コミット履歴を1行で表示
git log --author="<author>" 特定の著者のコミット履歴を表示
git log --since="<date>" 特定の日付以降のコミット履歴を表示
git log --grep="<pattern>" コミットメッセージに特定のパターンを含むコミット履歴を表示

ファイル操作

コマンド 説明
git rm <file> ファイルを削除し、ステージングエリアに反映
git mv <old> <new> ファイル名を変更し、ステージングエリアに反映

コミット操作

コマンド 説明
git commit --amend 直前のコミットを修正
git revert <commit> 指定したコミットを取り消すコミットを作成
git cherry-pick <commit> 指定したコミットを現在のブランチに適用

リセットとクリーン

コマンド 説明
git reset <file> ステージングエリアからファイルを取り消し
git reset --soft <commit> 指定したコミットまで変更を取り消し(ステージングエリアには残る)
git clean -df 未追跡のファイルとディレクトリを削除

サブモジュール

コマンド 説明
git submodule add <url> <path> サブモジュールを追加
git submodule update --init --recursive サブモジュールを初期化し、更新

その他

コマンド 説明
git stash 変更を一時的に退避
git stash pop 退避した変更を復元
git tag <tag> タグを作成
git reset --hard <commit> 指定したコミットまで変更を取り消し

Discussion