git常用命令

设置alias:

复制代码
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage "reset HEAD --"
git config --global alias.pl pull
git config --global alias.ps push
git config --global alias.rb rebase
git config --global alias.mr merge
git config --global alias.rs reset
git config --global alias.crp cherry-pick
git config --global alias.cl clone

以下是Git最常用的命令:

  1. 基础配置
bash 复制代码
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
  1. 仓库操作
bash 复制代码
git init            # 初始化仓库
git clone <url>     # 克隆远程仓库
git remote -v       # 查看远程仓库
  1. 基本操作
bash 复制代码
git status          # 查看仓库状态
git add <file>      # 添加文件到暂存区
git add .           # 添加所有改动到暂存区
git commit -m "message"  # 提交改动
git push           # 推送到远程仓库
git pull           # 拉取远程更新
  1. 分支操作
bash 复制代码
git branch          # 查看分支
git branch <name>   # 创建分支
git checkout <name> # 切换分支
git merge <branch>  # 合并分支
git branch -d <name> # 删除分支
  1. 查看信息
bash 复制代码
git log            # 查看提交历史
git diff           # 查看未暂存的更改
git show           # 查看某次提交的内容
  1. 撤销操作
bash 复制代码
git reset --hard <commit>  # 回退到某个版本
git checkout -- <file>     # 撤销工作区的修改
git reset HEAD <file>      # 撤销暂存区的修改
  1. 临时保存
bash 复制代码
git stash          # 临时保存当前工作
git stash pop      # 恢复最近的临时保存
  1. 标签操作
bash 复制代码
git tag            # 查看标签
git tag <name>     # 创建标签
git push origin <tagname>  # 推送标签到远程

这些是最常用的Git命令,它们能满足日常开发中90%的版本控制需求。建议重点掌握前3类命令,它们是最基础也是使用最频繁的。

相关推荐
小蒋观天下1 小时前
端侧大模型在安防摄像头部署实操(上)|行业痛点、架构选型、落地思路解析
大数据·人工智能·安全·计算机视觉·ai大模型
Elastic 中国社区官方博客1 小时前
使用 Lucene 搜索你的 Bean — 索引
java·大数据·数据库·elasticsearch·搜索引擎·全文检索·lucene
驭渊的小故事2 小时前
linux 基础命令 + git 仓库创建和配置命令
linux·git
马六六i2 小时前
市面上正规的IP驱动产业新场景新工具有哪些
大数据·网络·python·tcp/ip
AI副业教程3 小时前
加航 Aeroplan 定向活动:加拿大—欧洲高级舱额外 SQC 资讯整理(2026 秋季)
大数据
隔振降噪研究员4 小时前
振动筛振动治理科普
大数据·人工智能
阿部多瑞 ABU4 小时前
泛二次元问题舆论战与问题诸论
大数据·人工智能·ai写作
码云数智-园园4 小时前
码云数智、小鹅通、创客匠人知识付费小程序平台对比
大数据
成长之路5145 小时前
【数据集】全国500m分辨率实际蒸散发ET数据集(tif格式)2000-2025年
大数据
通信瓦工5 小时前
高功率密度AI数据中心的Mega AALC(高级辅助液体冷却)解决方案
大数据·人工智能