Git 中級
George Boorman
Curriculum Manager, DataCamp
| Command | Function |
|---|---|
git diff |
顯示所有未暫存檔與最新提交的差異 |
git diff report.md |
顯示單一未暫存檔與最新提交的差異 |
git diff --staged |
顯示所有已暫存檔與最新提交的差異 |
git diff --staged report.md |
顯示單一已暫存檔與最新提交的差異 |
git diff 35f4b4d 186398f |
以雜湊比較兩個提交的差異 |
git diff HEAD~1 HEAD~2 |
用 HEAD 位置比較兩個提交的差異 |
git diff main summary-statistics


space 繼續、按 q 離開git branch
main
* feature_dev
feature_dev
需要另一個分支來開發第二個新功能
解法:重新命名 feature_dev
重新命名分支
git branch -m
git branch
main
* feature_dev
feature_dev
需要另一個分支來開發第二個新功能
解法:重新命名 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).
要復原被刪除的分支很難,但並非不可能
刪除前務必確認不再需要!
| Command | Function |
|---|---|
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 中級