简述git
基础概念
工作流程
工作区——>暂存区——>版本库
- 工作区:直接编辑的目录
- 暂存区:中间阶段,可撤销更改,对应.git/index
- 版本库:最终存储内容的地方,对应.git
配置文件
以Windows为例:
C:\Users\用户名\AppData\Local\Programs\Git\etc\gitconfig
:系统配置文件,相当于git config --systemC:\Users\用户名\.gitconfig
:用户配置文件,相当于git config --globalD:\项目文件夹\.git\config
:项目配置文件,相当于git config
常用命令
# 配置git
git config --system # 系统配置
git config --global # 全局配置
git config # 项目配置
git config --global user.name "用户名" # 设置全局用户名
git config --global user.email 邮箱地址 # 设置全局邮箱
git config --global --unset user.name # 取消全局用户名设置
git config --global --edit # 编辑全局配置文件
git config --list # 显示配置信息
# 使用git
git init 仓库名 # 初始化git仓库
git add 文件名 # 把文件添加到暂存区
git commit -m '备注' # 把内容添加到版本库
git pull origin master # 同步远程仓库
git push origin master # 推送到远程仓库
git clone 仓库链接 # 拷贝仓库内容
# 诊断
git status # 查看仓库当前状态
# 分支管理
git branch 分支名 # 创建分支
git checkout 分支名 # 切换分支
git branch # 列出分支
git branch -d 分支名 # 删除分支