Git命令清单

本文提供了Git的常用操作指南,包括分支管理、提交、合并、撤销等关键命令,适合初学者快速上手及专业人士查阅。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html

 

重复commit 
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

解决:
git reset --hard origin/master


git config --global user.name "Your Name"
git config --global user.email "email@example.com"
ssh-keygen -t rsa -C "youremail@example.com"           id_rsa.pub为公钥

git status
git add .
git commit -s -a -m "message"
git review -R -v

git init
git push
git pull
git clone

追加
git commit --amend

版本回滚
git reset --hard 8d722bb
撤销工作区修改(未add):
git checkout -- 文件名
撤销对某文件的add(已add未commit,缓存区->工作区):
git reset HEAD 文件名


日志:
git log --pretty=oneline --abbrev-commit
--abbrev-commit:短id
查看历史命令:
git reflog
查看分支合并图
git log --graph

分支:
创建:
git branch 分支名
查看:
git branch -l
删除:
git branch -d 分支名
强行删除未合并分支:
git branch -D 分支名
切换:
git checkout 分支名
创建并切换
git checkout -b 分支名

合并分支到当前分支(conflicts冲突后手动解决冲突再 add commit);
git merge 分支名 
分支图会显示分支:
git merge --no-ff -m "合并信息" 分支名
git log --pretty=oneline --abbrev-commit --graph

保存现场;
git stash
恢复现场:
git stash pop


message:
feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试
chore:构建过程或辅助工具的变动

 

git commit --amend

切换远程分支并提交分支:
git clone ***
git branch release_1.1.2 remotes/origin/release_1.1.2
git checkout release_1.1.2

git review -R -v  release_1.1.2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值