ブランチの変更・比較

Git中級

George Boorman

Curriculum Manager, DataCamp

git diffまとめ

コマンド 機能
git diff ステージされていない全ファイルと最新コミットの差分を表示
git diff report.md ステージされていないファイルと最新コミットの差分を表示
git diff --staged ステージ状態のファイルと最新コミットの差分を表示
git diff --staged report.md ステージング済ファイルと最新コミットの差分を表示
git diff 35f4b4d 186398f 2つのコミット間の差分をハッシュで表示
git diff HEAD~1 HEAD~2 ハッシュの代わりにHEADで、2つのコミット間の差分を表示
Git中級

ブランチの比較

git diff main summary-statistics
Git中級

git diffの結果

git diff main summary-statistics output, truncated

Git中級

git diffの結果

git diff main summary-statistics output, second part

Git中級

長い出力の操作方法

*出力結果が長くなることがある

  • spaceを押してスクロール、qで終了
Git中級

ブランチの変更

git branch
  main
* feature_dev
  • feature_dev

  • 別の新機能開発用に、もう1つブランチが必要

  • 解決策:feature_devブランチの名前を変更する

  • ブランチの名前変更

git branch -m
Git中級

ブランチの名前変更

git branch
  main
* feature_dev
  • feature_dev

  • 別の新機能開発用に、もう1つブランチが必要

  • 解決策:feature_devブランチの名前を変更する

  • ブランチの名前変更
git branch -m feature_dev chatbot
Git中級

ブランチの確認

git branch
  main
* chatbot
Git中級

ブランチの削除

  • 大規模なプロジェクトだとブランチが多数になる

  • 作業が完了したブランチは削除する

  • -dフラグでchatbotブランチを削除する

git branch -d chatbot
Deleted branch chatbot (was 3edb989).
Git中級

マージされていないブランチの削除

  • chatbotmainにマージされていない場合、git branch -d chatbotを実行するとエラーになる
error: The branch 'chatbot' is not fully merged.
If you are sure you want to delete it, run 'git branch -D chatbot'.
  • -Dフラグで削除
git branch -D chatbot
Deleted branch chatbot (was 3edb989).
  • 削除されたブランチの復元は不可能ではないが、難しい

  • 削除する前に、不要であることを必ず確認する

Git中級

まとめ

コマンド 機能
git diff main chatbot mainchatbotブランチの状態を比較
git branch 全ブランチを一覧表示
git branch -m old_name new_name ブランチ名をold_nameからnew_name に変更
git branch -d chatbot マージ済みchatbotブランチを削除
git branch -D chatbot マージされていないchatbotブランチを削除
Git中級

練習しましょう!

Git中級

Preparing Video For Download...