Introduction
git 是一款版本管理软件,适用目前绝大多数操作系统;Github 是一个代码托管平台,与 Git 没有任何关系,只不过 Git 可以基于 Github 进行分布式云存储与交互,因此往往需要结合二者从而达到相对良好的 Teamwork 状态。本文是我基于 Git 的版本管理学习记录,涉及到的指令只是冰山一角,但是使用频率较高。详细的指令请跳转至官方教学 https://git-scm.com/book/zh/v2
全文分为两个部分,分别为 Git 版本管理的 Architecture 与 Git 的相关命令。其中 Architecture 使用 Xmind 绘制,Git 相关命令采用 Git Bash 模拟 Unix 命令行终端。本地 OS 为 Microsoft Windows 11
Architecture
Command
零、常用命令
| |
| git clone https://github.com/<UserName>/<ProjectName>.git |
一、配置
1.1 初始化
1.2 查看配置
| |
| git config user.name |
| git config user.password |
| git config user.email |
| |
| git config --global --get http.proxy |
| git config --global --get https.proxy |
1.3 编辑配置
| |
| git config user.name "xxx" |
| git config user.password "xxx" |
| git config user.email "xxx@xxx.com" |
| |
| |
| git config --global user.name xxx |
| git config --global user.password xxx |
| git config --global user.email "xxx@xxx.com" |
| |
| git config --global http.proxy 127.0.0.1:<VpnPort> |
| git config --global https.proxy 127.0.0.1:<VpnPort> |
| |
| |
| git config --global --unset http.proxy |
| git config --global --unset https.proxy |
| |
| git remote add <RemoteName> https://github.com/用户名/仓库名.git |
| |
| |
| git remote -v |
| |
| |
| git remote rename <OldRemoteName> <NewRemoteName> |
二、迭代
2.1 工作区到暂存区
| |
| git add <FileName> |
| |
| |
| git add . |
2.2 暂存区到仓库区
| |
| git commit -m '<Comment>' |
2.3 仓库区到服务器
| |
| git push <RemoteName> <BranchName> |
| |
| |
| git push -u <RemoteName> <BranchName> |
| |
| |
| git push |
| |
| git push --force <RemoteName> <BranchName> |
三、回溯
3.1 工作区到未修改状态
| |
| git checkout -- <FileName> |
3.2 暂存区到工作区状态
| |
| git reset -- <FileName> |
| |
| |
| git reset |
3.3 仓库区到暂存区状态
| |
| git reset --hard '<版本序列>' |
| |
| |
| git commit --amend |
3.4 取消服务器的修改
| |
| git rm <FileName> |
| git push |
| |
| |
| git rm -r <FolderName> |
| git push |
四、分支
4.1 创建分支
| |
| git branch <BranchName> |
| |
| |
| git push <RemoteName> <BranchName> |
4.2 删除分支
| |
| git switch <AnotherBranchName> |
| git branch -d <BranchName> |
| |
| |
| git push <RemoteName> --delete <BranchName> |
4.3 修改分支
如果修改的分支为远程保护分支,则在远程更新之前,需要在远程相应的服务商家那里对保护分支进行重新设定
| |
| git branch -m <OldName> <NewName> |
| |
| |
| git push <RemoteName> <NewName> |
| git push <RemoteName> --delete <OldName> |
4.4 合并分支
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】