dev-aid/git/cli.md
2023-02-24 14:55:14 +08:00

118 lines
1.9 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.

<h1>
Git
<h3>常用命令</h3>
</h1>
### 设置用户信息
```bash
git config --global user.name 'userName'
git config --global user.email service@yinghuasoft.com
```
### 克隆项目
```bash
git clone https://github.com/mick-xu/rapid-app.git
```
### 克隆名称为 "dev" 分支
```sh
git clone -b dev https://github.com/mick-xu/rapid-app.git
```
### 添加文件至暂存区
```bash
# 添加本地所有 untrack 的文件至暂存区
git add .
# 根据 .gitignore 过滤后添加 untrack 的文件至暂存区
git add *
```
### 提交至本地仓库
```bash
git commit -m [message]
git commit [file1] [file2] ... -m [message]
# 不需要执行 git add直接提交
git commit -a
# 跳过验证直接提交
git commit -m [message] --no-verify
git commit -m [message] -n
```
### 推送至远程仓库
```bash
git push
```
### 分支操作
```bash
# 查看远程分支
git branch -a
# 本地新建 "dev" 分支
git checkout -b dev
# 将本地 "dev" 分支推送至远程仓库
git push --set-upstream origin dev
# 切换至名称为 "dev" 的远程分支
$ git checkout -b dev origin/dev
```
### 初始化本地仓库,并推送至远程仓库
```bash
# 初始化
git init
# 添加 readme 文件
git add README.md
# 提交
git commit -m "first commit"
git remote add origin git@github.com:mick-xu/xxx.git
git push -u origin master
```
### 清除 git 缓存
```bash
git rm -r --cached .
```
### git commit type
```bash
feat: 增加新特性、新功能,
fix: 修补 bug,
perf: 性能,
style: 样式、格式,
docs: 文档变更,
test: 测试,
refactor: 重构,
build: 打包,
ci: ,
chore: 其他、日常事务,
revert: ,
wip: 正在开发中,
workflow: ,
types: ,
release: 发布
```
### git 密码错误被记录时清除缓存
```
# 适用于 Windows 系统
1、桌面左下角点击搜索工具搜索 Windows 凭据
2、打开 Windows 凭据,根据 Url 找到相关凭据删除
```