GIT 命令速查:最实用的 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
其他快捷参考
- Gitea 替代方案测试
- PowerShell 快捷参考
- cURL 快捷参考
- Bash 快捷表
- Hugo 快捷表
- Golang 快捷表
- LaTeX 快捷表
- Ollama 快捷表
- Docker 快捷表
- Kubernetes 快捷表
- [Python 快捷表](https://www.glukhov.org/zh-cn/post/2024/08/python-cheat-sheet/ “Python 快捷表”