一些常用到的git命令

git stash -a  //缓存所有文件
git stash pop //恢复所有缓存
git checkout -b dev origin/dev //切换到dev分支上,接着跟远程的origin地址上的dev分支关联起来

//推送本地分支到远程仓库
git push origin localbranchname:remotebrancname

git revert onefile //https://www.freecodecamp.org/news/git-revert-file-reverting-a-file-to-a-previous-commit/

//Git中获取当前分支名git
git branch --show-current

//git从指定的commit创建分支
git checkout -b branchname <commit-hash>

//以下两个命令需要在git bash下执行,因为window下找不到grep\xargs命令
//This script will delete all local branches except the master branch, including the non-merged branches.
git for-each-ref --format '%(refname:short)' refs/heads | grep -v "master\|main\|develop" | xargs git branch -D

//The -d is a soft delete option and only removes the merged branches.
git for-each-ref --format '%(refname:short)' refs/heads | grep -v "master\|main\|develop" | xargs git branch -d

//合并某个提交
git cherry-pick <commit-hash>

//列出包含某个提交的所有标签
git tag --contains f3a0b78
//克隆某个Tag的代码
git clone -b v9.2.2 https://gitlab.kitware.com/vtk/vtk.git


//回滚到某个提交
git log --oneline
git reset --hard <commit-hash>
git checkout -b branchname
git push origin localbranchname:remotebranchname

//如何撤销一个成功的“git cherry-pick”操作
https://geek-docs.com/git/git-questions/1519_git_how_to_undo_a_successful_git_cherrypick.html

在一个分支上连续解决多个问题:
1.git checkout -b branchname <commit-hash>
2.git commit 1
3.git push origin branchname:remotebranchname1
4.git reset --hard <commit>的上一个id,可通过git log查看,不用git revert,因为其会保留提交记录
5.git commit 2
6.git push origin branchname:remotebranchname2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dylan55_you

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值