GIT 常用命令速查表
带参数的 Git 命令 - 小型引用
目录
这里有一个小的快捷参考:带参数的 Git 命令
这张街道景观图片是由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>
等占位符替换为实际值。
有用的链接
- https://en.wikipedia.org/wiki/Git
- https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet
- https://about.gitlab.com/images/press/git-cheat-sheet.pdf
- https://education.github.com/git-cheat-sheet-education.pdf