Git 基础配置
2022-09-29 本文已影响0人
Tinyspot
1. 查看 Git 配置
- 帮助文档
$ git
查看配置
$ git config --list
修改 user.name/user.email
$ git config --global --replace-all user.name "your user name"
$ git config --global --replace-all user.email "your user email"
2. 初次配置
# 1. 设置用户名和邮箱
$ git config --global user.name "yourName"
$ git config --global user.email "email@example.com"
# 2. 生成密钥
$ ssh-keygen -t rsa -C "youremail@example.com"
# 按 3 个回车,密码为空
# 3. 添加 SSH 密钥 `id_rsa.pub`
查看密钥是否存在 $ cd ~/.ssh
3. Git 介绍
3.1 工作原理
- 工作目录、暂存目录(也叫做索引)和仓库
- 先提交到本地仓库,再推送到远程长裤

3.2 常用命令
git status
git add -A // 提交所有变化
git add -u // 提交被修改和被删除文件,不包括新文件(new)
git add . // 提交新文件和被修改文件,不包括被删除文件
git add file1 file2 file3
git clone
git checkout
git add // 将文件加入库跟踪区
git commit // 提交到本地代码库
git push // 提交到远程仓库