GIT 常用命令速查表

带参数的 Git 命令 - 小型引用

目录

这里有一个小的快捷参考:带参数的 Git 命令

街道景观上的“Git forever”横幅 这张街道景观图片是由AI模型Flux 1 dev生成的。

基本命令

  • git init: 初始化一个新的 Git 仓库
  • git clone <url>: 创建远程仓库的本地副本
  • git add <file>: 将更改暂存以提交
  • git commit -m "<message>": 使用信息将更改保存到本地仓库
  • git status: 检查工作目录的状态
  • git log: 查看提交历史

分支与合并

  • git branch: 列出所有本地分支
  • git branch <branch-name>: 创建一个新分支
  • git checkout <branch-name>: 切换到不同的分支
  • git checkout -b <branch-name>: 创建并切换到一个新分支
  • git merge <branch>: 将指定分支合并到当前分支

远程仓库

  • git remote add <name> <url>: 添加一个远程仓库
  • git push <remote> <branch>: 将本地提交上传到远程仓库
  • git pull: 从远程仓库获取并合并更改
  • git fetch: 从远程仓库下载更改

撤销更改

  • git reset <file>: 保留工作目录中的更改,但取消暂存
  • git reset --hard <commit>: 放弃所有更改并移动到特定提交
  • git revert <commit>: 创建一个新提交以撤销特定提交的更改

高级命令

  • git stash: 临时存储修改过的文件
  • git stash pop: 应用并删除最近的存储
  • git rebase <branch>: 在另一个基础上重新应用提交
  • git cherry-pick <commit>: 将特定提交应用到当前分支
  • git tag <tag-name>: 在当前提交上创建一个轻量标签

配置

  • git config --global user.name "<Your Name>": 设置提交时使用的名称
  • git config --global user.email "<you@example.com>": 设置提交时使用的电子邮件

在使用这些命令时,将类似 <file><url><branch-name> 等占位符替换为实际值。

有用的链接

其他快捷参考