Git 命令速查手册
2025/11/4 15:47:19 
来源:https://blog.csdn.net/2302_79590880/article/details/147354688 
浏览: 
次
 
关键词:Git 命令速查手册
听说用美图可以钓读者?
 

 
一、基础操作核心命令
 
1. 仓库初始化与克隆
 
| 命令 | 作用 | 示例 | 
|---|
git init | 创建新仓库 | git init my-project | 
git clone | 克隆远程仓库 | git clone [https://github.com/user/repo.git](https://github.com/user/repo.git) | 
git remote add | 关联远程仓库 | git remote add origin [https://github.com/user/repo.git](https://github.com/user/repo.git) | 
 
2. 文件操作
 
| 命令 | 作用 | 示例 | 
|---|
git add | 添加文件到暂存区 | git add .(添加所有) | 
git rm | 删除文件 | git rm file.txt | 
git mv | 重命名文件 | git mv old.txt new.txt | 
 
 
二、配置管理(含代理)
 
1. 多层级配置
 
| 命令 | 作用 | 示例 | 
|---|
git config --global | 全局配置 | git config --global user.name "John" | 
git config --local | 仓库级配置 | git config --local core.autocrlf false | 
git config --list | 查看配置 | git config --list --show-origin | 
 
2. 代理管理
 
| 类型 | 命令 | 示例 | 
|---|
| HTTP代理 | git config http.proxy | git config --global http.proxy [http://127.0.0.1:7890](http://127.0.0.1:7890) | 
| 域名级代理 | git config http.[url].proxy | git config --global http.[https://github.com.proxy ](https://github.com.proxy )socks5://127.0.0.1:1080 | 
| 清除代理 | git config --unset | git config --global --unset http.proxy | 
 
 
三、提交与版本控制
 
1. 提交操作
 
| 命令 | 作用 | 示例 | 
|---|
git commit -m | 标准提交 | git commit -m "feat: add login" | 
git commit --amend | 修改提交 | git commit --amend --no-edit | 
git rebase -i | 交互式变基 | git rebase -i HEAD\~3 | 
 
2. 版本追溯
 
| 命令 | 作用 | 示例 | 
|---|
git log | 查看历史 | git log --oneline --graph | 
git diff | 对比差异 | git diff HEAD\~1 HEAD | 
git blame | 追踪修改 | git blame config.ini | 
 
 
四、分支与协作
 
1. 分支管理
 
| 命令 | 作用 | 示例 | 
|---|
git branch | 查看分支 | git branch -av | 
git checkout -b | 创建分支 | git checkout -b dev | 
git merge --no-ff | 保留合并历史 | git merge dev --no-ff | 
 
2. 远程协作
 
| 命令 | 作用 | 示例 | 
|---|
git push -u | 推送并关联 | git push -u origin main | 
git pull --rebase | 变基式拉取 | git pull --rebase | 
git fetch --prune | 清理远程分支 | git fetch --prune | 
 
 
五、高级操作速查
 
1. 撤销与恢复
 
| 命令 | 作用 | 场景 | 
|---|
git checkout -- [file] | 撤销工作区修改 | 未暂存时恢复 | 
git reset --soft | 撤销提交保留修改 | git reset HEAD\~1 | 
git reflog | 找回误删提交 | git reflog | 
 
2. 代理验证方法
 
| 操作 | 命令 | 输出验证 | 
|---|
| 检查代理配置 | git config --get-regexp 'proxy' | 显示生效代理地址 | 
| 测试SSH代理 | ssh -Tv git@github.com | 查看代理握手日志 | 
| 流量监控 | sudo lsof -i :7890 | grep git | 确认git使用代理端口 | 
 
  
 
 
 
完结散花。