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

相关推荐
weixin_3077791316 小时前
Git中获取一个目录下所有文件的最后修改人的邮箱
开发语言·git·算法
ynchyong21 小时前
Git 急救指南:手滑 add / commit 错了,怎么优雅地撤回
git·手滑
Zucker n2 天前
Git 常用命令速查(自用笔记)
git
雪碧聊技术2 天前
Git实战:在Idea中,如何只将分支 A 某次 Commit记录的单个文件同步到分支 B?一文详解|保姆教程
git·文件对比,一键应用
Mortalbreeze2 天前
Git 基础篇(三):分支管理
git
Zucker n2 天前
安装 Git for Windows(自用笔记)
笔记·git
棒子胡豆2 天前
Git总结
git
`流年づ4 天前
联邦学习-安全聚合
git·安全·github
喜欢吃燃面5 天前
Git 原理与使用(三):标签、多人协作与 Git Flow 落地
大数据·git·elasticsearch
喜欢吃燃面5 天前
Git 原理与使用(二):分支是平行宇宙,远程仓库是共享时空
大数据·git·elasticsearch