Git 常用命令

Git 常用命令

设置查看:

git config --list  # 查看所有 
git config user.name  # 查看用户名 
git config --local --list  # 查看仓库级别配置
git config --global --list  # 查看用户级别配置

用户名和邮箱:

1. --local
作用范围:当前 Git 仓库
保存位置:Git 仓库的 .git/config
git config --local user.name "Your Name"
git config --local user.email "youremail@example.com"

2. --global
作用范围:当前用户
保存位置:该用户主目录下的 .gitconfig
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

3. --system
作用范围:系统
保存位置:/etc/gitconfig
注意:对所有用户和所有 Git 仓库都有效,一般需要sudo权限
sudo git config --system core.editor "nano"

4. 不带参数
读取/写入顺序:仓库级别 > 用户级别 > 系统级别
git config user.name "Your Name"
git config user.email "your.email@example.com"

查看项目状态:

git status

文件修改提交到本地暂存区:

git add <filename1> <filename2>  # 提交某个文件
git add -A  # 提交全部

提交当前工作空间的修改内容:

git commit -m "提交说明"  # 本地

add、commit 撤销:

git reset --soft HEAD^  # commit 撤销
git reset HEAD  # add 撤销

pull、push:

git pull origin <branchname>
git pull <url> <branchname>

git push origin <branchname> # 把已经commit的内容传到远程服务器
git push <url> <branchname>

# url 查看
git remote -v

分支:

git branch  # 查看本地分支
git branch -r  # 查看远程分支
git branch -vv  # 查看分支合并状态

git checkout <branch_name>  # 切换到存在分支
git checkout -b <new_branch_name>  # 创建并切换到新的分支

git fetch origin  # 切换到远程分支1:先拉取
git checkout origin/<branch_name>  # 切换到远程分支2:后切换
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值