一、配置用户信息
$git config --global user.name 'your_name'$git config --global user.email 'your_email@domain.com'
config的三个作用域
$ git config --local只对当前仓库有效$ git config --global对当前用户所有仓库有效$ git config --system对系统所有仓库有效
显示config配置信息,加—list
$ git config --list --local$ git config --list --global$ git config --list --system二、建Git仓库
两种场景:
1.把已有的项目代码纳入Git仓库
$ cd 项目代码所在的文件夹$ git init
2.新建的项目直接用Git管理
$ cd 某个文件夹 $ git init you_project #会在当前陆金霞简历和项目名称同名的文件夹 $ cd you_project
三、认识Git的工作目录、暂存区、版本历史

工作区、暂存区、HEAD、commit
- 工作区提交暂存去
$git add filename$git add .
- 工作区恢复暂存区
$git checkout -- filename
- 暂存区提交
$git commit -m 'remark'
- 暂存区恢复HEAD
$git reset HEAD$git reset HEAD -- filename
- 回退到某个commit
$git reset --hard commit1
四、查看版本库
$git log$git log --oneline$git log -n2$git log --all查看所有分支的commit$git log --all --graph查看图形化分支
五、分支
$git branch -v查看分支$git checkout -b branchname新建分支$git checkout branchname切换分支$git checkout -d branchname删除分支
六、HEAD
- 分离头指针:当先看某个 commit 的 code 使用
checkout切换的这个 commit 时。HEAD没有指向分支时 - 单新建分支或者切换分支时,HEAD会指向分支,而分支会指向最后退出commit
七、比对diff
$git diff HEAD HEAD~1$git diff commit1 commit2$git diff --cached暂存区和commit比较$git diff工作区和暂存区比较$git diff -- filenames工作区和暂存区的文件比较
八、修改commit提交信息
$git commit --amend修改最近一次提交信息$git rebase -i commitparent修改之前的提交信息
九、添加不需要git管理文件
.gitignore
十、提交仓库
$git remote -v查看绑定仓库$ git remote add [name] [uri]添加仓库
探秘.git目录
- COMMIT_EDITMSG:保存了最后提commit提交信息
- HEAD :记录当前所在分支
- config :local配置信息
- refs:
- heads: 存放所有分支
- master:记录分支指向的commit索引
- ….
- tags
- heads: 存放所有分支
- objects
- commit
- tree
- tree/imges
- blob/index.*
- parent
- author
- committer
- tree
- commit

