Git 本地版本管理操作教程
本文介绍 Git 的基础安装与常见本地版本管理操作流程,包括克隆仓库、提交、分支管理等。
1. 安装 Git
下载安装 Git 官网 提供的安装包,按提示安装。
2. 配置 Git 用户信息
git config –global user.name “你的用户名”
git config –global user.email “你的邮箱”
3、创建或者克隆仓库用于保存版本
克隆仓库
mkdir my_project
cd my_project
git init
保存版本
git clone https://github.com//username/project.git
4、把需要进行版本管理的文件添加到仓库
git add filename
git add .
5、提交更改
git commit -m "commit message"
6、查看状态和提交历史
git status (查看提交状态)
git log(查看提交历史)
7、分支管理
git branch new-branch-name
git checkout new-branch-name(切换到指定分支)
git checkout main(回到main分支)
git merge new-branch-name(合并分支)
8、添加远程仓库
git remote add origin https://github.com/username/rep.git
git push origin main(推送更改到远程仓库)
9、回溯版本
git log
git check abc1234(找到回溯ID)
git checkout main(回到最新状态)
10、其余操作
git diff(查看未提交的更改)
git branch new-feature(开发分支)
通过以上操作,可以在本地进行版本管理,随时进行代码的回溯与更新!
Git 本地版本管理操作教程