dev-aid/git/cli.md
2023-10-18 19:26:47 +08:00

2.0 KiB
Raw Blame History

Git

常用命令

设置用户信息

git config --global user.name 'userName'
git config --global user.email service@yinghuasoft.com

克隆项目

git clone https://github.com/mick-xu/rapid-app.git

克隆名称为 "dev" 分支

git clone -b dev https://github.com/mick-xu/rapid-app.git

添加文件至暂存区

# 添加本地所有 untrack 的文件至暂存区
git add .

# 根据 .gitignore 过滤后添加 untrack 的文件至暂存区
git add *

提交至本地仓库

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

推送至远程仓库

git push

分支操作

# 查看远程分支
git branch -a

# 本地新建 "dev" 分支
git checkout -b dev

# 将本地 "dev" 分支推送至远程仓库
git push --set-upstream origin dev

# 切换至名称为 "dev" 的远程分支
$ git checkout -b dev origin/dev

初始化本地仓库,并推送至远程仓库

# 初始化
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 缓存,解决添加 .gitignore 不生效的问题

git rm -r --cached .

git commit type

feat: 增加新特性、新功能,
fix: 修补 bug,
perf: 性能,
style: 样式、格式,
docs: 文档变更,
test: 测试,
refactor: 重构,
build: 打包,
ci: ,
chore: 其他、日常事务,
revert: ,
wip: 正在开发中,
workflow: ,
types: ,
release: 发布

git 密码错误被记录时清除缓存

# 适用于 Windows 系统
1、桌面左下角点击搜索工具搜索 Windows 凭据

2、打开 Windows 凭据,根据 Url 找到相关凭据删除

添加安全目录

git config --global --add safe.directory E:/repos/github/rapid