一些常用到的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

相关推荐
胡西风_foxww9 小时前
git 添加除了包含特定字符串的文件
git·字符串·文件·add·添加·特定·包含
parade岁月9 小时前
Git 凭据管理器原理与多账号管理指南
git
zzzyulin9 小时前
git note
git
六件套是我9 小时前
【解答疑惑】git执行cherrypick后到另一个分支,然后再合并会出现问题吗?
git
sulikey1 天前
从零配置一个规范的 Python Git 仓库(适用于 Gitee / GitHub)
git·python·pycharm·gitee·github
学渣676561 天前
【面向小白】git rebase全面总结,什么时候用rebase
git
小龙报1 天前
《算法每日一题(1)--- 第31场蓝桥算法挑战赛》
c语言·开发语言·c++·git·算法·学习方法
222you1 天前
idea整合Git
git
今禾1 天前
Git完全指南(下篇):Git高级技巧与问题解决
前端·git·github
Molesidy1 天前
【Git】【TortoiseGit】TortoiseGit安装与基础使用
git