前言
Git 指令大全,涵盖了日常开发中常用的操作
1. 初始化与配置
初始化一个 Git 仓库
git init
- 1
设置 Git 用户名
git config --global user.name "Your Name"
- 1
设置 Git 邮箱
git config --global user.email "youremail@example.com"
- 1
查看当前配置
git config --list
- 1
2. 版本管理
查看版本历史
git log
- 1
查看简洁的版本历史
git log --oneline
- 1
查看某个文件的修改历史
git log <file-path>
- 1
查看文件的更改
git diff
- 1
查看暂存区与工作区的区别
git diff --cached
- 1
3. 分支管理
创建新分支
git branch <branch-name>
- 1
切换分支
git checkout <branch-name>
- 1
创建并切换到新分支
git checkout -b <branch-name
- 1
查看所有分支
git branch
- 1
删除本地分支
git branch -d <branch-name>
- 1
强制删除本地分支
git branch -D <branch-name>
- 1
4、暂存与提交
将文件添加到暂存区
git add <file-path>
- 1
添加所有修改过的文件到暂存区
git add .
- 1
提交修改
git commit -m "Commit message"
- 1
查看暂存区和工作区的差异
git status
- 1
撤销暂存区的修改
git reset <file-path>
- 1
5、远程仓库操作
查看当前远程仓库
git remote -v
- 1
添加远程仓库
git remote add origin <repository-url>
- 1
推送代码到远程仓库
git push origin <branch-name>
- 1
拉取远程仓库的代码
git pull origin <branch-name>
- 1
从远程仓库克隆代码
git clone <repository-url>
- 1
6、 合并与变基
合并分支
git merge <branch-name>
- 1
变基操作(将一个分支的修改放到另一个分支上)
git rebase <branch-name>
- 1
7、标签管理
查看所有标签
git tag
- 1
创建标签
git tag <tag-name>
- 1
推送标签到远程仓库
git push origin <tag-name>
- 1
删除本地标签
git tag -d <tag-name>
- 1
删除远程标签
git push --delete origin <tag-name>
- 1
8、 回退与重置
回退到上一个提交
git checkout -- <file-path>
- 1
重置到某个版本(软重置、硬重置)
git reset --hard <commit-id>
- 1
撤销最近一次提交,但保留文件
git reset --soft HEAD~1
- 1
丢弃所有本地更改
git checkout .
- 1
9、解决冲突
查看冲突文件
git status
- 1
标记冲突已解决
git add <resolved-file>
//完成合并
git commit
- 1
- 2
- 3
10、其他常用指令
查看当前 Git 配置
git config --list
- 1
清理未使用的文件
git clean -f
- 1
查看当前分支的日志
git log --oneline --graph --decorate --all
- 1
这些是 Git 最常用的一些命令,可以帮助你有效地管理项目的版本控制。
9092

被折叠的 条评论
为什么被折叠?



