一些常用到的git命令

git stash -a //缓存所有文件

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

相关推荐
int WINGsssss13 小时前
Git使用
git
用户07605303543815 小时前
Git Revert:安全移除错误提交的方式
git
Good_Starry1 天前
Git介绍--github/gitee/gitlab使用
git·gitee·gitlab·github
云端奇趣1 天前
探索 3 个有趣的 GitHub 学习资源库
经验分享·git·学习·github
F_D_Z2 天前
【解决办法】git clone报错unable to access ‘xxx‘: SSL certificate problem:
网络·git·网络协议·ssl
等风来不如迎风去2 天前
【git】main|REBASE 2/6
git
艾伦~耶格尔2 天前
IDEA 配置 Git 详解
java·ide·git·后端·intellij-idea
云兮杜康2 天前
IDEA中用过git之后文件名颜色全变红
java·git·intellij-idea
睡不醒的小泽2 天前
git merge 和 git rebase
git
艾伦~耶格尔2 天前
Git 下载及安装超详教程(2024)
git·gitee·码仓