🌍 GIT 命令使用手册
2025年9月13日大约 2 分钟WindowsWindows
版本库命令详解
# 初始化当前工作区
git init
# 查了当前工作区的状态
git status
# 添加文件到暂存
git add <filename>
# 提交所有变化到暂存
git add -A
# 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)到暂存
git add -u
# 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件到暂存,Ps:在Git 2.x版本中 `git add .` === `git add -A`
git add .
# 将存入暂存区修改内容提交至本地仓库中
git commit -m <本地提交的描述>
# 提交所有修改到暂存,并提交到本地仓库
git commit -am <本地提交的描述>
分支命令详解
# 列出所有分支,当前分支前面会标一个*号
git branch
# 创建新分支
git branch <branch name>
# 切换到指定分支
git checkout <branch name>
# 创建新分支,并切换到新分支,例如:git checkout -b dev === git branch dev && git checkout dev
git checkout -b <branch name>
# 拉去远端的指定分支到本地
git checkout -b <local branch name> origin/<origin branch name>
合并分支命令详解
# 当前分支合并指定分支
git merge <branch name>
# 删除指定分支
git branch -d <branch name>
# 删除远端分支,分支前的冒号代表删除
git push origin :<branch name>
添加远端地址命令详解
# 添加远端仓库地址
git remote add origin <远端地址>
# 提交到远端分支
git push -u origin <branch name>
# 查看有哪些远端分支
git branch -a
# 删除指定远端分支
git push origin --delete <远端分支名称>
版本回退命令详解
# 显示提交日志,展示不那么漂亮
git log
# 查看提交日志,在一行展示,更漂亮
git log --pretty=oneline
# 通过git log 查看提交历史以确定要回到的位置,并拿到想回到的commit id 执行之
git reset --hard [commit id]
# 查看所有执行的git命令 可以用来查找回滚之前的 commit id 在使用git reset --hard 回滚过去
git reflog
标签
# 切换到需要打标签的分支
git checkout <branch name>
git tag <tag name> [commit id]
# 给当前commit创建一个新标签
git tag v0.0.1
# 给指定commit创建一个新标签
git tag v0.9.0 f52c633
# 查看所有标签命令详解
git tag
# 给指定标签指定信息
git tag -a <tagname> -m ["标签信息"]
远端标签
# 推送指定标签到远端
git push origin <tag name>
# 推送全部未推送的标签到远端
git push origin --tags
删除指定标签
# 删除本地指定标签
git tag -d <tag name>
# 删除远端指定标签
git push origin :refs/tags/<tag name>
忽略已入库文件的修改
# 忽略已入库的filename文件的修改
git update-index --assume-unchanged [filename]
# 反操作
git update-index --no-assume-unchanged [filename]