目录
版本管理的演变
VCS : Version Control System (版本控制系统)
一、VCS 出现前
⽤⽬录拷⻉区别不同版本
公共⽂件容易被覆盖
成员沟通成本很⾼,代码集成效率低下
二、集中式 VCS
有集中的版本管理服务器,具备⽂件版本管理和分⽀管理能⼒
集成效率有明显地提⾼
客户端必须时刻和服务器相连
三、分布式 VCS
服务端和客户端都有完整的版本库
脱离服务端,客户端照样可以管理版本
查看历史和版本⽐较等多数操作,都不需要访问服务器
⽐集中式 VCS 更能提⾼版本管理效率
Git
一、Git的特点
最优的存储能⼒
⾮凡的性能
开源的
很容易做备份
⽀持离线操作
很容易定制⼯作流程
二、安装Git
1、参考:Git安装
进入官网,按照提示选择对应平台进行安装
2、Mac 可通过以下几种方式安装
Download for macOS
There are several options for installing Git on macOS. Note that any non-source distributions are provided by third parties, and may not be up to date with the latest source release.
Homebrew
Install homebrew if you don’t already have it, then:
$ brew install git
Xcode
Apple ships a binary package of Git with Xcode.
Binary installer
Tim Harper provides an installer for Git. The latest version is 2.27.0, which was released 5 months ago, on 2020-07-22.
Building from Source
If you prefer to build from source, you can find tarballs on kernel.org. The latest version is 2.29.2.
Installing git-gui
If you would like to install git-gui and gitk, git’s commit GUI and interactive history browser, you can do so using homebrew
$ brew install git-gui
3、检查安装结果
在 bash 下执⾏下⾯的命令,看是否返回 git 的版本
$ git --version
git version 2.19.0
三、Git基本配置
1、config 的三个作用域
//local只对仓库有效
git config --local
//global对登录⽤户所有仓库有效
git config --global
//system对系统的所有⽤户有效
git config --system
缺省值:local
优先级:local > global > system
2、显示config的配置信息
//查看所有配置信息
git config --list
//查看当前仓库配置信息
git config --list --local
//查看当前登录用户配置信息
git config --list --global
//查看系统所有用户配置信息
git config --list --system
//查看local的user.name和user.email
git config user.name
git config user.email
3、配置user信息
git config user.name 'your_name'
git config user.email 'your_email@domain.com'
git config --global user.name 'your_name'
git config --global user.email 'your_email@domain.com'
git config --system user.name 'your_name'
git config --system user.email 'your_email@domain.com'
4、清除 –unset
git config --unset --local user.name
git config --unset --global user.name
git config --unset --system user.name
四、动手试一试
请动⼿⽐⼀⽐,local 和 global 的优先级。
- 在 Git 命令⾏⽅式下,⽤ init 创建⼀个 Git 仓库。
$ git init your_first_git_repo_name
- cd 到 repo 中。
$ cd your_first_git_repo_name
- 配置 global 和 local 两个级别的 user.name 和 user.email。
$ git config --local user.name 'your_local_name' $ git config --local user.email 'your_local_email@.' $ git config --global user.name 'your_global_name' $ git config --global user.name 'your_global_eamil@.'
- 创建空的 commit
$ git commit --allow-empty -m ‘Initial’
- ⽤ log 看 commit 信息,Author 的 name 和 email 是什么?
$ git log
行者常至,为者常成!