欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > Git 命令速查手册

Git 命令速查手册

2025/4/23 5:11:52 来源: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.proxygit config --global http.proxy [http://127.0.0.1:7890](http://127.0.0.1:7890)
域名级代理git config http.[url].proxygit config --global http.[https://github.com.proxy ](https://github.com.proxy )socks5://127.0.0.1:1080
清除代理git config --unsetgit 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使用代理端口

 

完结散花。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词