Git常用操作指令

  1. 初始化配置

    配置全局用户名和邮箱

    git config --global user.name "账号"
    git config --global user.email "邮箱"

    查看配置信息

    git config --list

  2. 仓库初始化创建新的 Git 仓库:

    初始化新仓库

    git init

    克隆远程仓库

    git clone URL

  3. 状态查看实时了解仓库状态:

    查看工作区状态

    git status

    查看简化状态信息

    git status -s

    查看本地分支

    git branch

    查看远程分支

    git branch -r

    查看本地和远程所有分支

    git branch -a

  4. 添加和提交基本的版本控制操作:

    添加指定文件到暂存区

    git add

    添加所有更改

    git add .

    提交到本地仓库

    git commit -m "commit message"

    添加并提交

    git commit -am "commit message"

    移除暂存区的提交

    git reset
    git reset

    将提交推送到远程仓库

    git push

    将本地当前分支提交到远程指定分支remote-branch

    git push origin remote-branch

  5. 分支操作:

    创建新分支

    git branch

    切换分支

    git checkout

    创建并切换分支

    git checkout -b

    删除分支

    git branch -d

  6. 远程仓库操作与远程仓库交互:

    添加远程仓库

    git remote add origin

    查看远程仓库

    git remote -v

    推送到远程

    git push origin

    拉取远程更新

    git pull origin

  7. 分支合并:

    #提交brancheA某次的commit merge到指定分支branchB
    git log brancheA 获取到需要merge 的commit 的哈希值 hash
    git checkout branchB
    git cherry-pick hash
    git status 查看是否已经更新
    git push 将更新推送到远程

    合并分支

    git merge

    变基操作

    git rebase

    解决冲突后继续变基

    git rebase --continue

  8. 暂存操作临时保存工作进度:

    保存当前工作进度

    git stash

    查看存储的工作进度

    git stash list

    恢复最近的进度

    git stash pop

    删除所有进度

    git stash clear

  9. 日志查看查看提交历史:

    查看提交日志

    git log

    查看简化日志

    git log --oneline

    查看图形化日志

    git log --graph --pretty=oneline --abbrev-commit

  10. 差异比较比较:

    查看工作区和暂存区的差异

    git diff

    查看暂存区和最新提交的差异

    git diff --staged

    查看两个分支的差异

    git diff

  11. 撤销操作修正错误操作:

    撤销工作区的修改

    git checkout --

    撤销暂存区的修改

    git reset HEAD

  12. 日常工作流程

    更新本地代码

    git pull origin main

    创建功能分支

    git checkout -b feature/new-feature

    推送到远程

    git push origin feature/new-feature

相关推荐
北极象10 分钟前
Adobe全家桶被AI克隆,github地址
adobe·github
来自于狂人2 小时前
GitHub 开源趋势日报 | 2026年10月9日
开源·github
wflynn3 小时前
GitHub 今日推荐|wordcraft:用 Rust 重写 Word 内核并开放给 AI 调用
rust·开源·github
用户813267933254 小时前
行情数据晚到几秒,会让量化策略失去优势吗?从信号时间到回测偏差
后端·github·api
MicrosoftReactor4 小时前
技术速递|使用 GitHub Security Lab Taskflow Agent 实现 AI 驱动的模糊测试
人工智能·ai·github·copilot·agent·模糊测试·ai-agent
QuantiCore_IO4 小时前
从请求风暴到可维护的数据管道:量化系统为什么需要批量接口?
后端·github·api
用户813267933254 小时前
量化系统为什么不应该为每只股票单独写一套数据获取逻辑?
后端·github·api
asong5 小时前
没有源代码,AI 也能拆解软件:这个开源项目已有 3.7 万 Star
javascript·后端·github
七牛云行业应用5 小时前
GitHub 94k Star 工具 Agent Reach:给 AI Agent 装上互联网能力,零 API 费用接入 13 个平台
人工智能·github
沐言人生5 小时前
82.4k 星!把十几万行代码变成知识图谱,新人终于不用硬啃了
前端·后端·github