Git 常用指令速查表
 
 - Git 常用指令速查表
 - 目录
 - 1. 初始化仓库
 - 2. 提交代码流程
 - 3. 分支管理
 - 4. 远程仓库操作
 - 5. 撤销操作
 - 6. 查看状态与日志
 - 7. 其他实用指令
 - 完整操作示例
 - 常用场景速查表
 
 
 
 
  
 
Git 常用指令速查表
 
目录
 
- 初始化仓库
 - 提交代码流程
 - 分支管理
 - 远程仓库操作
 - 撤销操作
 - 查看状态与日志
 - 其他实用指令
 
 
1. 初始化仓库
 
git init
git clone <远程仓库 URL>
 
2. 提交代码流程
 
git add .
git add file1.txt file2.md
git commit -m "提交说明:修复登录 bug"
git commit --no-verify -m "紧急提交"
 
3. 分支管理
 
git branch
git branch new-feature
git checkout existing-branch
git checkout -b new-branch
git merge target-branch
git branch -d local-branch
git branch -D local-branch
git push origin --delete remote-branch
 
4. 远程仓库操作
 
git remote -v
git remote add origin <远程仓库 URL>
git pull origin target-branch
git push origin current-branch
git push --force
 
5. 撤销操作
 
git reset HEAD file.txt
git checkout -- file.txt
git reset --soft HEAD^
git reset --hard HEAD^
git revert HEAD
 
6. 查看状态与日志
 
git status
git log
git log --oneline
git diff
 
7. 其他实用指令
 
echo "*.log" >> .gitignore
git stash
git stash pop
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
 
完整操作示例
 
git clone git@github.com:your-username/repo.git
git checkout -b feature/login
git add .
git commit -m "实现登录功能"
git push origin feature/login
git checkout main
git pull
git merge feature/login
git push
 
常用场景速查表
 
| 场景 | 指令 | 
|---|
| 创建仓库 | git init / git clone | 
| 提交代码 | git add . && git commit -m "说明" | 
| 分支开发 | git checkout -b new-branch | 
| 同步远程代码 | git pull origin main | 
| 撤销本地修改 | git checkout -- file / git reset --hard | 
| 解决冲突 | 手动修改后 git add . && git commit | 
| 查看历史 | git log --graph --decorate |