Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions docs/src/appendix-git-commands-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,21 @@ git commit --amend -m "新しいメッセージ"
### ファイルの取り消し・復元

```bash
# ワーキングディレクトリの変更を取り消し
git checkout -- <ファイル名>
# ワーキングツリーの変更を取り消し(推奨)
git restore <ファイル名>

# ステージングから除外(変更は保持)
git reset HEAD <ファイル名>
# ステージングから除外(変更は保持)(推奨)
git restore --staged <ファイル名>

# 最新コミットから特定ファイルを復元
git checkout HEAD -- <ファイル名>
# 最新コミット(HEAD)から特定ファイルを復元(推奨)
git restore --source HEAD -- <ファイル名>

# 指定コミットから特定ファイルを復元
git checkout <コミットハッシュ> -- <ファイル名>
# 指定コミットから特定ファイルを復元(推奨)
git restore --source <コミットハッシュ> -- <ファイル名>
```

※ 古い解説では `git checkout -- <ファイル名>` の形式を見かけることがあります。現在は「ブランチ切り替え」は `git switch`、「ファイル復元」は `git restore` に分けると意図が伝わりやすくなります。

---

## A.3 ブランチ操作
Expand All @@ -112,20 +114,18 @@ git checkout <コミットハッシュ> -- <ファイル名>
# 新しいブランチを作成
git branch <ブランチ名>

# ブランチを作成して切り替え
git checkout -b <ブランチ名>
# ブランチを作成して切り替え(推奨)
git switch -c <ブランチ名>

# リモートブランチベースで作成・切り替え
git checkout -b <ローカルブランチ名> origin/<リモートブランチ名>
# リモートブランチベースで作成・切り替え(推奨)
git switch -c <ローカルブランチ名> origin/<リモートブランチ名>

# ブランチの切り替え
git checkout <ブランチ名>

# Git 2.23以降の新しい構文
# 既存ブランチの切り替え(推奨)
git switch <ブランチ名>
git switch -c <新しいブランチ名>
```

※ 古い解説では `git checkout -b` や `git checkout <ブランチ名>` を使う例もあります。いずれも動作しますが、本書では `git switch` を推奨形として扱います。

### ブランチの管理

```bash
Expand Down Expand Up @@ -496,7 +496,7 @@ git pull && git status
git add -A && git commit -m "機能実装完了" && git push

# ブランチ切り替え前の安全確認
git status && git stash && git checkout main
git status && git stash && git switch main
```

### デバッグ・調査用
Expand Down
14 changes: 5 additions & 9 deletions docs/src/chapter-git-basics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,9 @@ Update files

### 基本的なブランチ操作

**新しいブランチの作成:**
**新しいブランチの作成と切り替え(推奨):**
```bash
git branch feature-new-design
git checkout feature-new-design
```

**または、作成と切り替えを同時に:**
```bash
git checkout -b feature-new-design
git switch -c feature-new-design
```

**ブランチの一覧確認:**
Expand All @@ -186,9 +180,11 @@ git branch

**メインブランチに戻る:**
```bash
git checkout main
git switch main
```

※ 古い解説では `git checkout` を使う例もあります。現在はブランチ切り替えに `git switch`、ファイル復元に `git restore` を使うと意図が伝わりやすくなります(付録Aも参照してください)。

### ブランチの活用例

**シナリオ:**個人ブログのデザインを変更したい
Expand Down