Git 是程序员必备的版本控制工具,本文整理了一些常用的 Git 命令,方便日常查阅。
基础配置
1 2 3 4 5 6
| git config --global user.name "你的名字" git config --global user.email "你的邮箱"
git config --list
|
常用命令
克隆与初始化
1 2 3 4 5
| git clone <url>
git init
|
日常操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| git status
git add . git add <file>
git commit -m "提交信息"
git push origin main
git pull origin main
|
分支管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| git branch
git branch <branch-name>
git checkout <branch-name>
git checkout -b <branch-name>
git merge <branch-name>
git branch -d <branch-name>
|
回退操作
1 2 3 4 5 6 7 8 9 10 11
| git checkout -- <file>
git reset HEAD <file>
git reset --hard HEAD^
git log --oneline
|
小技巧
- 使用
git stash 暂存当前工作
- 使用
git cherry-pick <commit> 选择性合并提交
- 使用
.gitignore 忽略不需要跟踪的文件
持续更新中…