- 初始化仓库:
git init
- 添加文件到暂存区:
git add <file>
- 添加所有文件到暂存区:
git add .
- 提交更改:
git commit -m "Commit message"
- 查看提交历史:
git log
- 克隆仓库:
git clone <repository-url>
- 查看当前分支:
git branch
- 切换分支:
git checkout <branch-name>
- 创建新分支:
git branch <branch-name>
- 合并分支:
git merge <branch-name>
- 删除分支:
- 删除已经合并的分支:
git branch -d <branch-name>
- 强制删除未合并的分支(小心使用):
git branch -D <branch-name>
- 查看更改:
- 查看工作目录中的更改:
git status
- 查看未暂存的更改:
git diff
- 查看已暂存的更改:
git diff --staged
- 撤销更改:
- 撤销最后一次提交(撤销工作目录中的更改):
git reset --soft HEAD^1
- 撤销暂存区的更改:
git reset <file>
- 撤销工作目录和暂存区的更改:
git checkout -- <file>