玩转Git三剑客
1.剑客之家
-
Git 官网:https://git-scm.com
-
GitHub: https://github.com
-
GitLab:https://about.gitlab.com/
-
SVN: https://subversion.apache.org/
2.git安装
- Git 官方文档地址:https://git-scm.com/book/zh/v2
- macOS平台下载地址:https://git-scm.com/download/mac
- windows平台下载地址:https://git-scm.com/download/win
- Linux平台下载地址:https://git-scm.com/download/linux
3.使用Git之前需要做的最小配置
(1).添加配置
git config [–local | –global | –system] user.name ‘Your name’ |
git config [–local | –global | –system] user.email ‘Your email’ |
(2).查看配置
git config –list [–local | –global | –system] |
(3).config 的三个作⽤域的区别
- local:区域为本仓库
- global: 当前用户的所有仓库(最常用,其余两个很少用)
- system: 本系统的所有用户
(4).清除配置
$ git config --unset --local user.name
$ git config --unset --global user.name
$ git config --unset --system user.name
(5).优先级
local > global > system
4.创建第一个仓库并配置local用户信息
(1).Git仓库的两种方式
-
⽤ Git 之前已经有项⽬代码
$ cd 项⽬代码所在的⽂件夹 $ git init
-
⽤ Git 之前还没有项⽬代码
$ cd 某个⽂件夹
$ git init your_project #会在当前路径下创建和项⽬名称同名的⽂件夹
$ cd your_project
复制文件夹 cp -r
复制文件 cp
(3).git add
git add .:将工作空间新增和被修改的文件添加的暂存区 git add -u:将工作空间被修改和被删除的文件添加到暂存区(不包含没有纳入Git管理的新增文件)
5.文件重命名
更加高效的方式(一步搞定)
git mv readme readme.md
6.通过git log 查看版本演变历史
- git log –all 查看所有分支的历史
- git log –all –graph 查看图形化的 log 地址
- git log –oneline 查看单行的简洁历史。
- git log –oneline -n4 查看最近的四条简洁历史。
- git log –oneline –all -n4 –graph 查看所有分支最近 4 条单行的图形化历史。
- git help –web log 跳转到git log 的帮助文档网页
(1).查看分支信息
(2).gitk:通过图形界面工具来查看版本历史
7. 探密.git目录
//cat命令主要用来查看文件内容,创建文件,文件合并,追加文件内容等功能。
- cat HEAD 查看HEAD文件的内容
- git cat-file 命令 显示版本库对象的内容、类型及大小信息。
- git cat-file -t b44dd71d62a5a8ed3 显示版本库对象的类型
- git cat-file -s b44dd71d62a5a8ed3 显示版本库对象的大小
- git cat-file -p b44dd71d62a5a8ed3 显示版本库对象的内容
HEAD:指向当前的工作路径
config:存放本地仓库(local)相关的配置信息。
refs/heads:存放分支
refs/tags:存放tag,又叫里程牌 (当这次commit是具有里程碑意义的 比如项目1.0的时候 就可以打tag)
objects:存放对象 .git/objects/ 文件夹中的子文件夹都是以哈希值的前两位字符命名 每个object由40位字符组成,前两位字符用来当文件夹,后38位做文件。