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

相关推荐
cen__y7 小时前
Linux12(Git01)
linux·运维·服务器·c语言·开发语言·git
bukeyiwanshui10 小时前
20260518 Swift实验
git·swift
qziovv10 小时前
Git 回退场景
大数据·git·elasticsearch
来自大山深处的Doge_13 小时前
解决Git提交更新更改时出错: detected dubious ownership in repository at ...
git
嵌入式爱好者hsw15 小时前
Git 部署本地仓库
git
C137的本贾尼16 小时前
Git基本操作(三):版本回退,坐上“时光机”
git
ylifs17 小时前
目的驱动式Git用法
git
来尔君18 小时前
Git Bash 提示符简化(就是每次敲命令时上面显示的那一行信息)
git·命令行
我叫张小白。19 小时前
PyCharm 集成 Git 与 Gitee
git·pycharm·gitee
小雨青年19 小时前
Git Bisect 实战:用二分法快速找到引入 Bug 的提交
git·bug