$Git Simulator
壊しても大丈夫。全部ブラウザの中だけで動いています

コマンド チートシート

このシミュレーターで使えるコマンドを場面別にまとめました。すべて本物の Git と同じ書き方です。本物の Git で使う便利なオプションや、シミュレーターに無いコマンドは 実務でよく使うコマンド を参照してください。

始める

git init                                  # このフォルダをリポジトリにする
git clone <URL>                           # リモートを複製する
git config user.name "名前"               # 作者名(本物では --global を付けて一度設定)
git config user.email "メール"
git config --global init.defaultBranch main   # 本物の Git で最初のブランチを main にする

状態を見る

git status                # いまの状態(迷ったらこれ)
git status -s             # 短縮表示
git diff                  # ワークツリー ↔ ステージ
git diff --staged         # ステージ ↔ HEAD
git diff <a> <b>          # コミット/ブランチ間
git diff <a> <b> -- <file>   # ファイルを絞る

記録する

git add <file>            # ステージに載せる
git add .                 # 全部載せる
git commit -m "メッセージ"
git commit -am "メッセージ"   # 追跡済みファイルを add + commit
git commit --amend -m "..."  # 直前のコミットを作り直す

履歴を見る

git log                   # 詳細
git log --oneline         # 1 行ずつ
git log --oneline --graph --all   # 全ブランチをグラフで
git log -3                # 最新 3 件
git show <commit>         # コミットの内容と差分
git show HEAD~1           # 1 つ前
git reflog                # HEAD の移動履歴(復旧用)

ブランチ

git branch                # 一覧
git branch -a             # リモート追跡ブランチも
git branch -v             # 最新コミット付き
git switch -c <name>      # 作って移動
git switch <name>         # 移動
git switch -              # 直前のブランチへ
git branch -d <name>      # 削除(マージ済み)
git branch -D <name>      # 強制削除
git branch -m <new>       # 現在のブランチをリネーム

マージ・rebase

git merge <branch>        # 現在のブランチに取り込む
git merge --no-ff <branch>   # 必ずマージコミットを作る
git merge --abort         # マージを中止
git rebase <branch>       # 現在のブランチを branch の上に載せ直す
git rebase --continue     # コンフリクト解消後に続行
git rebase --abort        # rebase を中止
git cherry-pick <commit>  # 特定のコミットだけ取り込む

取り消す

git restore <file>            # 編集を捨てる(⚠️)
git restore --staged <file>   # ステージから降ろす
git reset --soft HEAD~1       # コミット取り消し、変更はステージに
git reset HEAD~1              # コミット取り消し、変更はワークツリーに
git reset --hard HEAD~1       # コミットも変更も捨てる(⚠️)
git reset --hard <commit>     # そのコミットの状態に戻す(⚠️)
git revert <commit>           # 打ち消すコミットを作る(push 済みはこれ)
git rm <file>                 # ファイルを削除して記録
git rm --cached <file>        # 追跡だけ外す(ファイルは残す)
git mv <old> <new>            # リネーム

一時退避

git stash                 # 変更を退避
git stash list            # 一覧
git stash pop             # 戻して消す
git stash apply           # 戻すが残す
git stash drop            # 消す

リモート

git remote -v                     # 登録一覧
git remote add origin <URL>       # 登録
git push -u origin <branch>       # 初回 push(送り先を記憶)
git push                          # 2 回目以降
git push origin --delete <branch> # リモートのブランチを削除
git fetch                         # 情報を取得(ファイルは変えない)
git pull                          # fetch + merge
git pull --rebase                 # fetch + rebase

本物の Git で分岐した状態から git pull するには、先に git config --global pull.rebase false(merge)か true(rebase)を設定しておきます。

タグ

git tag                   # 一覧
git tag v1.0              # 現在のコミットにタグ
git tag -d v1.0           # 削除

シェル(このシミュレーター)

ls / ls -a                # ファイル一覧
cat <file>                # 中身を表示
echo "text" > <file>      # 書き込み(上書き)
echo "text" >> <file>     # 追記
echo -e "1\n2" > <file>   # 複数行
touch <file>              # 空ファイル
rm <file>                 # 削除
vim <file>                # エディタを開く
tree                      # ツリー表示
clear                     # 画面を消す(Ctrl+L)
help                      # コマンド一覧

キーボード: ↑↓ で履歴、Tab で補完、Ctrl+C で入力を消す、Ctrl+L で画面クリア。

「これが分からない」の対応表

症状見るところ
add と commit の違いが分からない3 つのエリア
HEAD~1 って何コミットと HEAD
ブランチを切り替えたらファイルが消えたブランチとマージ
CONFLICT と出たコンフリクト
push が rejected されたリモートリポジトリ
PR って何をすればいいのプルリクエスト
壊した気がするやり直しと復旧
入れたくないファイルが status に出る.gitignore を使いこなす
自分の PC で Git を始めたいインストールと初期設定
用語の意味が分からない用語集