1、全局配置
a、告诉git当前用户的姓名和邮箱
git config --global user.name "heaiming“
git config --global user.email "576439313@qq.com"
b、设置git命令别名
git config --global alias.st status
c、git命令输出开启颜色显示
git config --global color.ui true
d、删除Git全局配置文件
git config --unset --global user.name
2、版本库
a、创建:git init [dir目录]
b、显示隐藏目录:ls -af
c、添加到暂存区:git add testone.txt
d、提交到本地库:git commit -m "add hello to testone.txt”
e、工作区内搜索内容:git grep “hello"
3、.git目录
当在git工作区的某个子目录下执行操作的时候,会在工作区目录中依向上递归查找.git目录,找到的
.git目录:工作区对应的版本库
.git所在的目录就是工作区的根目录
文件.git/index:记录了工作区文件的状态(实际上是暂存区的状态)
如果找不到就会报错。
a、显示版本库.git目录所在位置:git rev-parse --git-dr
b、显示工作区根目录:git rev-parse --show-toplevel
c、相对于工作区根目录的相对目录:git rev-parse --show-prefix
d、显示从当前目录(cd)后退(up)到工作区的根的深度:git rev-parse --show-cdup
4、git config命令参数
格式:INI文件格式
a、编辑.git/config文件:git config -e(版本库级别的配置文件)
b、编辑用户主目录下的.gitconfig文件 全局配置文件:git config -e --global(全局配置文件)
c、编辑系统级的配置文件:git config -e --system(系统级配置文件)
优先级:版本库级别的配置文件>全局配置文年>系统级别的配置文件
d、读取INI配置文件内容:git config <section>.<key> git config core.base
f、更改或设置INI文件中某个属性的值:git config <section>.<key> <value> git config a.b something
g、git Config操作其他INI文件:
向配置文件test.ini中添加配置
$GIT_CONFIG=test.ini git config a.b.c.d "hello,world"
读取test.ini中的配置
$GIT_CONFIG=test.ini git config a.b.c.d
5、提交用户
git config --unset --global user.name
git config --global user.name smile
a、允许执行空白提交:git commit --allow-empty -m "who does commig??"
b、查看版本库的提交日志:git log --pretty=fuller
c、重新修改最新的提交:git commit --amend --allow-empty --reset-author
--amend 对刚刚的提交进行修补
--allow-empty 允许空白提交
--reset-author 将提交者的Id同步修改,否则只会影响提交者的Id。同时会重置AuthorDate信息
