git-learner/notes/notes.md
2024-08-15 21:32:28 +02:00

105 lines
2.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# git 权威指南
## 2.1 Git 初始化
### 2.1.1 创建版本库以及第一次提交
```git
git config --global user.name "Hanzhang Ma"
git config --global user.email "cxyoz@outlook.com"
```
创建别名
```bash
$ sudo git config --system alias.br branch
$ sudo git config --system alias.ci "commit -s"
$ sudo git config --system alias.co checkout
$ sudo git config --system alias.st "-p status"
```
初始化, 在当前文件夹下新建一个demo的仓库
```bash
git init demo
```
展示所有文件夹里的内容
```bash
ls -aF
```
git会依次向上递归查找.git文件夹来找到根版本库
```bash
strace -e 'trace=file' git status
```
```bash
git rev-parse --git-dir # .git目录所在位置
git rev-parse --show-toplevel #工作区根目录
git rev-parse --show-cdup # 到工作区根目录的方式
```
### 2.1.3 git config参数的区别
Git的三个配置文件分别是
- 版本库级别的配置文件、
- 全局配置文件(用户主目录下)和
- 系统级配置文件(/etc目录下
其中版本库级别配置文件的优先级最高,全局配置文件其次,系统级配置文件优先级最低。这样的优先级设置就可以让版本库.git目录下的config文件中的配置可以覆盖用户主目录下的Git环境配置。而用户主目录下的配置也可以覆盖系统的Git配置文件。
编辑每种配置文件的方式
```bash
cd /path/to/myworkspace/
git config -e
```
```bash
git config -e --global#全局
git config -e --system#系统,可能需要sudo权限
```
git config文件类似这样
```text
[a]
b = something
[x "y"]
z = others
```
删除配置中的某一项
```bash
git config --unset --global
git config --unset --system
git config --unset
```
### 2.1.4 谁完成的提交
允许空白提交,即没有文件修改的提交
```bash
git commit --allow-empty -m "who does commit"
```
查看git日志包含作者提交日期
```bash
git log --pretty=fuller
```
修改最新一条commit的作者指令
```bash
git commit --amend --allow-empty --reset-author
```
`--amend`表示对最后一个提交进行修补