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 中级