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

相关推荐
家里有只小肥猫1 天前
git回退某条/多条提交记录
git
何中应1 天前
IDEA 中让 Git 忽略 .idea 目录
java·git·intellij-idea
小柯博客1 天前
从零开始打造 OpenSTLinux 6.6 Yocto 系统 - STM32MP2(基于STM32CubeMX)(六)
c语言·git·stm32·单片机·嵌入式硬件·开源·yocto
静若繁花_jingjing1 天前
Git分支命令
git
stu_kk1 天前
Git常用操作指令
git
顾默@1 天前
关于git推送到远程仓库的一些操作
git
___波子 Pro Max.1 天前
Git 2.23新增命令switch使用指南
git
℘团子এ2 天前
git中,项目怎么更换远程仓库连接地址
git
言之。2 天前
Git Hooks
git
代码AI弗森2 天前
Git Bash 与 PowerShell:定位差异、使用场景与选择建议
开发语言·git·bash