git常用操作大全

1. git diff

  • 不接参数,顺序展示多个文件的差异内容(和暂存区内容对比);
  • 接参数filename,展示指定文件的差异内容(和暂存区内容对比);
  • 接参数--cached,暂存区和本地仓库进行对比。

2. git checkout -b branch_name

  • 创建一个新的本地分支

3. git branch -vv

  • 查看本地分支的跟踪情况

4. git branch -a

  • 查看所有分支(包括远程分支)

5. git branch -D branch_name

  • 删除本地分支

6. git push origin --delete branch_name

  • 删除远程分支

7. git fetch origin branch_name

  • 拉取远程分支的更新,但不会合并到本地仓库

8. git merge origin/ branch_name

  • 拉取远程分支的更新之后,使用merge操作合并到本地。

9. git merge branch_name

  • merge其他分支的修改,可能会出现冲突。

10. git log

  • 默认的方式查看提交记录

11. git log --color --graph --pretty='%Cred%h %C(yellow)%ad %C(reset)%cn %C(bold blue)%B %Cgreen%d' --date=short

  • 自定义日志格式,格式化参数含义请参考此处

12. git config --global alias.lg "log --color --graph --pretty='%Cred%h %C(yellow)%ad %C(reset)%cn %C(bold blue)%B %Cgreen%d' --date=short"

  • 配置全局日志格式

13. git config --global --list

  • 显示全局配置

14. git config --global --unset alias.lg

  • 删除别名配置

15. git cherry-pick commit_id1 commit_id2

  • 根据指定commit_id进行合并

16. git rebase start_id end_id -i --onto branch_name

  • 对指定commit_id范围内的commit进行合并操作。

17. git reset

  • 撤销暂存区的修改

18. git reset HEAD

  • 撤销本地仓库和暂存区的最新提交

19. git reset --hard commit_id

  • 工作区、暂存区和本地仓库恢复到指定提交点

20. git checkout -- filename

  • 撤销工作区的修改

21. git reflog

  • 包括回滚和删除的提交记录在此处都能看到。

22. git log --oneline

  • 只展示一行log信息,用于快速浏览日志

23. git log origin/branch_name

  • 查看远程分支的提交记录

24. git show commit_id

  • 展示指定提交修改内容
相关推荐
ShineWinsu11 小时前
对于Git:远程操作的超详细保姆级解析
linux·git·gitee·github·远程仓库·分布式版本控制系统·远程操作
梦帮科技12 小时前
从 Guest 到 Platinum:Prompt 配额、API Key 与访问控制的安全闭环
javascript·git·架构·node.js·reactjs·html5·visual studio
zho_uzhou1 天前
Git入门概念
git
爱奥尼欧2 天前
【Git】远程分支删了本地还在、两个分支历史不相干?两招故障排解
开发语言·git
Java后端的Ai之路2 天前
Git冲突完整排查与实战:本地修改覆盖报错到成功推送全流程复盘
开发语言·人工智能·git·python·pop
一个心烑2 天前
配置项目git的 SSL 证书
git·网络协议·ssl
IT从业者张某某2 天前
【鸿蒙PC命令行适配】GitUI 移植的工程实践:双 Git 引擎(libgit2/gitoxide)的鸿蒙适配之路
git·华为·harmonyos
xinjia_ctrl2 天前
暑假实习总结
git·后端·spring·maven·intellij-idea
Molesidy2 天前
【Git】分别给出添加到Keil工程和IAR工程中的gitnore文件以便不跟踪编译文件的git记录
git·vscode·插件
颜颜yan_2 天前
Git Cola 鸿蒙 PC 版适配全记录:从 Qt 桌面工具到 ArkTS 原生应用
git·qt·harmonyos