Git 常用命令速查
程序员文章站
2022-03-07 09:33:49
...
Git 常用命令速查
英文 | 含义 |
---|---|
master | 默认开发分支 |
Head | 默认开发分支 |
origin | 默认远程版本库 |
Head^ | Head的父提交 |
文章目录
1. 创建版本库
1.1 克隆远程版本库
git clone <url>
1.2 初始化本地版本库
git init
2. 修改和提交
2.1 查看状态
git status
2.2 查看变更内容
git diff
2.3 跟踪所有改动过的文件
git add .
2.4 跟踪指定的文件
git add <file>
2.5 文件改名
git mv <old> <new>
2.6 删除文件
git rm <file>
2.7 停止跟踪文件但不删除
git rm --cached <file>
2.8 提交所有更新过的文件
git commit -m "commit message"
2.9 修改最后一次提交
git commit --amend
3. 查看提交历史
3.1 查看提交历史
git log
3.2 查看指定文件的提交历史
git log -p <file>
3.3 以列表方式查看指定文件的提交历史
git blame <file>
4. 撤销
4.1 撤销工作目录中所有未提交文件的修改内容
git reset --hard HEAD
4.2 撤销指定的未提交文件的修改内容
git checkout HEAD <file>
4.3 撤销指定的提交
git revert <commit>
5. 分支与标签
5.1 显示所有本地分支
git branch
5.2 切换到指定分支或者标签
git checkout <branch/tag>
5.3 创建新分支
git branch <new-branch>
5.4 删除本地分支
git branch -d <branch>
5.5 列出所有本地标签
git tag
5.6 基于最新提交创建标签
git tag <tag-name>
5.7 删除标签
git tag -d <tag-name>
6. 合并和衍合
6.1 合并指定分支到当前分支
git merge <branch>
6.2 衍合指定分支到当前分支
git rebase <branch>
7. 远程操作
7.1 查看远程版本库信息
git remote -v
7.2 查看指定远程版本库信息
git remote show <remote>
7.3 添加远程版本库
git remote add <remote> <url>
7.4 从远程库获取代码
git fetch <remote>
7.5 下载代码及快速合并
git pull <remote> <branch>
7.6 上传代码及快速合并
git push <remote> <branch>
7.7 删除远程分支及标签
git push <remote> :<branch/tag-name>
7.8 上传所有标签
git push --tags
下一篇: 网络设备结构体net_device介绍