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 列表中移除
相关推荐
呆萌很1 小时前
Git push 408 超时、远程断开解决办法
git
Lesile2 小时前
Hands-on Git experience
git
Co_Hui3 小时前
Git 基本使用
git
cooldream20093 小时前
AI 时代,Git 应该怎么学
人工智能·git
柒和远方5 小时前
V053: 从 Git 回退到 AI 工程治理:Vibe Coding 的 Harness 工作流与质量阀门
git·vibecoding
炸膛坦客7 小时前
Git 和 GitHub:(五)一文给出常用 Git 命令,持续更新中......
git·github
门前大桥下.8 小时前
从git创建新分支后推送数据同步新的分支
git
触底反弹18 小时前
Vibe Coding 不写 Git,等于悬崖边飙车
人工智能·git·面试
泡沫冰@19 小时前
基于Git、Jenkins、Podman、ECS的CI/CD实践
git·jenkins·podman
zfoo-framework20 小时前
git拦截大于5M文件
git