Git命令总结

廖雪峰的Git教程总结

😀基本命令

命令 作用
git add <file> 将文件更新添加到暂存区
git commit -m "message" 将当前暂存区的内容添加到版本库生成一个commit
git status 展示工作区和暂存区的状态
git diff 比较工作区和暂存区的差异
git log 显示从最近到最远的提交日志
git reset --hard HEAD^ 回退到上一个版本
git checkout -- file 丢弃工作区的修改(一种是无暂存内容丢弃工作区修改,一种是有暂存内容丢弃工作区修改)
git reset HEAD <file> 把暂存区的修改撤销放回工作区

🙂远程仓库相关命令

命令 作用
ssh-keygen -t rsa -C "[email protected]" 创建SSH Key,在用户主目录里找到.ssh目录,在github中添加id_rsa.pub的内容
git remote add origin [email protected]:acezsq/learngit.git 关联远程仓库,给远程仓库命名为origin
git push -u origin master 向远程仓库推送master分支的所有内容。
git push 第一次git push加-u参数后续直接git push即可
git pull 拉取远程仓库最新内容到本地
git remote rm origin 解除了本地和远程的绑定关系
git remote -v 查看远程库信息
git clone [email protected]:acezsq/dsx-rl.git 克隆远程仓库到本地

😘分支相关命令

命令 作用
git branch 查看分支
git branch <name> 创建分支
git switch <name> 切换分支
git switch -c <name> 创建+切换分支
git merge <name> 合并某分支到当前分支
git branch -d <name> 删除分支
git log --graph 查看分支合并图
git cherry-pick <commit> 把bug提交的修改"复制"到当前分支
git branch -D <name> 丢弃一个没有被合并过的分支
git checkout -b dev origin/dev 远程库clone后创建远程origin的dev分支到本地
git rebase 将一个分支的修改应用到另一个分支上,并且可以重写提交历史,把分叉的提交历史"整理"成一条直线

😄其他命令

命令 作用
git log --pretty=oneline 显示简化的提交日志
git reflog 查看命令历史以确定要回到未来哪个版本
git reset --hard commit_id 回到某个特定的版本,--hard 参数会强制更新你的工作区和暂存区,丢弃任何未提交的更改
git diff --staged 比较暂存区与最新提交的差异
git diff <commit> 比较当前工作区与指定提交之间的差异
git diff <commit1> <commit2> 比较两个不同提交之间的差异
git checkout <name> 切换分支
git checkout -b <name> 创建+切换分支
git log --graph --pretty=oneline --abbrev-commit 查看分支合并图
git merge --no-ff -m "merge with no-ff" dev 禁用Fast forward模式进行合并
git stash git stash 会将工作目录和暂存区中的修改都暂时保存起来,并将工作目录和暂存区恢复到最后一次提交的状态
git stash list 已经保存的 stash 列表
git stash apply 应用最近的 stash
git stash apply stash@{0} 恢复指定的stash
git stash pop 应用最近的 stash 并将其从 stash 列表中移除
相关推荐
ice___Cpu3 小时前
Git - 1( 14000 字详解 )
大数据·git·elasticsearch
范纹杉想快点毕业19 小时前
以项目的方式学QT开发(一)——超详细讲解(120000多字详细讲解,涵盖qt大量知识)逐步更新!
c语言·数据结构·c++·git·qt·链表·github
qq_6536444621 小时前
如何查看打开的 git bash 窗口是否是管理员权限打开
开发语言·windows·git·bash
tonngw21 小时前
【Mac 从 0 到 1 保姆级配置教程 12】- 安装配置万能的编辑器 VSCode 以及常用插件
git·vscode·后端·macos·开源·编辑器·github
橄榄熊1 天前
Git 常用命令详解
git
o(╥﹏╥)2 天前
绑定 SSH key(macos)
开发语言·git·学习·macos
半新半旧2 天前
Git 分支指南
git
qq_464357012 天前
git中忽略文件.gitignore文件的用法
git
程序员阿鹏2 天前
Git的安装和配置(idea中配置Git)
java·开发语言·ide·git·intellij-idea·idea
belldeep3 天前
如何阅读、学习 Git 核心源代码 ?
git·学习·源代码