Git中級
George Boorman
Curriculum Manager, DataCamp
| コマンド | 機能 |
|---|---|
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 diff main summary-statistics


*出力結果が長くなることがある
spaceを押してスクロール、qで終了git branch
main
* feature_dev
feature_dev
別の新機能開発用に、もう1つブランチが必要
解決策:feature_devブランチの名前を変更する
ブランチの名前変更
git branch -m
git branch
main
* feature_dev
feature_dev
別の新機能開発用に、もう1つブランチが必要
解決策:feature_devブランチの名前を変更する
git branch -m feature_dev chatbot
git branch
main
* chatbot
大規模なプロジェクトだとブランチが多数になる
作業が完了したブランチは削除する
-dフラグでchatbotブランチを削除する
git branch -d chatbot
Deleted branch chatbot (was 3edb989).
chatbotがmainにマージされていない場合、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 diff main chatbot |
mainとchatbotブランチの状態を比較 |
git branch |
全ブランチを一覧表示 |
git branch -m old_name new_name |
ブランチ名をold_nameからnew_name に変更 |
git branch -d chatbot |
マージ済みのchatbotブランチを削除 |
git branch -D chatbot |
マージされていないchatbotブランチを削除 |
Git中級