Git使用总结

Git常用命令

git本地仓库

命令 作用 备注
git init 初始化本地仓库
git add < file > 添加修改 把修改的内容提交到暂存区
git commit -m < message > 提交修改 把暂存区的内容提交到当前分区
git diff 查看修改
git restore < file > 撤销工作区修改
git restore --staged < file > 撤销暂存区修改
git rm < file > 删除文件
git status 查看状态
git log 查看日志 如果要显示的内容过多,按'q'键可退出分页显示
git reflog 查看历史命令
git reset 回退版本 可设置参数: --hard <版本号,如:601934****>,回退到指定的版本 --hard HEAD~<N,如:1、2、3...>,以HEAD为基准回退N个版本

git远程仓库

命令 作用 备注
git remote add master git@github.com:***o/learngit.git 本地仓库关联远程仓库
git push -u master master 把本地仓库内容推送到远程仓库 第一次
git push 把本地仓库内容推送到远程仓库 后续
git remote -v 查看关联的远程仓库版本
git remote rm master 删除关联的远程仓库 解除本地仓库与远程仓库的关联关系

常见问题

  • Q: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.
    • A: 执行 ssh-keygen -t rsa -C "youremail@example.com"

      把生成的id_rsa.pub文件中的内容添加到远程仓库中

相关推荐
Python私教2 小时前
Git 撤销与回退避坑指南:reset / revert / restore 到底用哪个(2026 实战)
git
流浪0012 小时前
Linux篇(九):一文搞懂 Git:版本控制的原理与实操指南
git
Ws_4 小时前
Git + Gerrit 第九课:cherry-pick 挑选提交
git
之歆6 小时前
Day04_Git完全指南:从入门到精通的版本控制精通
git
码出财富6 小时前
InsForge 后端分支管理实战指南
git
2601_961194026 小时前
2026六级词汇PDF下载|大学英语六级单词表+音频PDF
windows·git·eclipse·pdf·github
幽冥三王爷8 小时前
Git 操作常见问题与处理办法
git
独挽离人10 小时前
git标准推送流程
git
无人生还别怕10 小时前
搭建gitlab服务并接入openldap认证
git·gitlab·github·openldap·ldap·统一认证
努力努力再努力wz11 小时前
【Qt入门系列】一文掌握 Qt 常用显示类控件:QLCDNumber、QProgressBar 与 QCalendarWidget
c语言·开发语言·数据结构·数据库·c++·git·qt