修改与比较分支

Git 中级

George Boorman

Curriculum Manager, DataCamp

diff 回顾

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

比较分支

git diff main summary-statistics
Git 中级

git diff 输出

git diff main summary-statistics 输出(截断)

Git 中级

git diff 输出

git diff main summary-statistics 输出,第二部分

Git 中级

浏览大型 git 输出

  • 可能产生很长的输出!
  • space 继续,按 q 退出
Git 中级

修改分支

git branch
  main
* feature_dev
  • feature_dev

  • 正在开发第二个新功能,需要另一个分支

  • 方案:重命名 feature_dev

  • 重命名分支

git branch -m
Git 中级

重命名分支

git branch
  main
* feature_dev
  • feature_dev

  • 正在开发第二个新功能,需要另一个分支

  • 方案:重命名 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 中级

删除未合并的分支

  • chatbot 未合并到 maingit 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 中级

总结

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

Passons à la pratique !

Git 中级

Preparing Video For Download...