1.git的基础
1.1 什么是git
Git是一个版本管理控制系统(缩写VCS),它可以在任何时间点,将文档的状态作为更新记录保存起来,也可以在任何时间点,将更新记录恢复回来。
1.2什么是版本管理
版本管理是一种记录文件变化的方式,以便将来查阅特定版本的文件内容。
2.git的使用
2.1git 使用前配置
- 配置提交人姓名:git config --global user.name 提交人姓名
- 配置提交人姓名:git config --global user.email 提交人邮箱
- 查看git配置信息:git config --list (分别查看 git config user.name || git config user.email)
注意 - 如果要对配置信息进行修改,重复上述命令即可。
- 配置只需要执行一次。
2.2提交步骤
- git init 初始化git仓库 (mac中Command+Shift+. 可以显示隐藏文件)
- git status 查看文件状态
- git add 文件列表 追踪文件
- git commit -m 提交信息 向仓库中提交代码
- git log 查看提交记录
2.3撤销
用暂存区中的文件覆盖工作目录中的文件: git checkout --文件名
将文件从暂存区中删除: git rm --cached 文件名
将 git 仓库中指定的更新记录恢复出来,并且覆盖暂存区和工作目录:git reset --hard commitID
2.4分支命令
git branch 查看分支
git branch 分支名称 创建分支
git checkout 分支名称 切换分支
git merge 来源分支 合并分支 (备注:必须在master分支上才能合并develop分支)
git branch -d 分支名称 删除分支(分支被合并后才允许删除)(-D 强制删除)
2.5暂时保存更改
在git中,可以暂时提取分支上所有的改动并存储,让开发人员得到一个干净的工作副本,临时转向其他工作。
使用场景:分支临时切换
存储临时改动:git stash
恢复改动:git stash pop