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 "youremail@example.com" 创建SSH Key,在用户主目录里找到.ssh目录,在github中添加id_rsa.pub的内容
git remote add origin git@github.com: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 git@github.com: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 列表中移除
相关推荐
云闲不收21 小时前
git rebase
git
江上清风山间明月21 小时前
git pull和git checkout在恢复文件的区别
git·pull·checkout
海鸥811 天前
in argocd ‘/tmp/_argocd-repo/../.git/index.lock‘: No space left on
git·argocd
尔嵘1 天前
git操作
大数据·git·elasticsearch
好评1241 天前
Linux文件上传git
linux·运维·git
大柏怎么被偷了1 天前
【Git】企业级开发模型
git
Garfield20051 天前
Git 分支拓扑实践
git·拓扑
DKNG1 天前
【Windows Host】 hosts配置增加访问github流畅度
人工智能·git·github
一个很帅的帅哥1 天前
git命令大全
大数据·git·elasticsearch
凯子坚持 c1 天前
Git 远程仓库操作与深度进阶指南
git