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]

  • 展示指定提交修改内容
相关推荐
青靴12 小时前
轻量级 CI/CD:Git Hooks 自动部署 Node.js 应用(CICD-demo)
git·ci/cd·node.js
哟哟耶耶13 小时前
git-git cherry-pick(从分支挑选特定提交-哈希值)更改应用到当前分支
git
无限进步_15 小时前
C语言动态内存管理:掌握malloc、calloc、realloc和free的实战应用
c语言·开发语言·c++·git·算法·github·visual studio
程序员馨馨19 小时前
git常用命令学习以及冲突解决
git·功能测试·学习
1***81531 天前
Git游戏开发案例
git
likuolei1 天前
Git 工作区、暂存区和版本库
数据库·git
HAPPY酷1 天前
git配置及使用
git
sg_knight1 天前
IntelliJ IDEA 实用插件:GitToolBox 使用指南
java·ide·git·intellij-idea·插件·gittoolbox
青靴1 天前
Git Hooks 实现 CI/CD 进阶实践 -- 根据实际需求添加功能
git·elasticsearch·ci/cd
LiuYaoheng1 天前
Git配置SSH Key到GitHub的详细教程
git·ssh·github