Docs/Git/git基础.md
2023-05-23 17:15:28 +08:00

47 lines
No EOL
1 KiB
Markdown
Raw 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.

## 配置
```shell
# --global全局配置所有仓库生效
# --system系统配置所有用户生效
git config --global user.name "xxxxxx"
git config --global user.email "xxxxx"
# 存储用户名密码
git config --global credential.helper store
# 查看
git config --global --i
```
## 创建
```shell
git init
```
## 查看提交日志
```shell
git log
git log --oneline
```
## 查看暂存区
```shell
git ls-files
```
## 回退
```shell
# 回退到某个版本,并保留工作区与暂存区的所有修改内容
git reset --soft <version>
# 回退到某个版本,并丢弃工作区与暂存区的所有修改内容
git reset --hard <version>
# 回退到某个版本,只保留工作区的内容
git reset --mixed <version>
```
## 查看差异
```shell
# 默认比较工作区与暂存区的差异
git diff
# 工作区与版本库的差异
git diff HEAD
# 暂存区与版本库差异
git diff cached
# 两次提交的差异
git diff xxx xxxx1
# 之前两个版本的差异
git diff HEAD~ HEAD
git diff HEAD^ HEAD
```