本地仓库
初始化仓库
1 | git init |
查看文件状态
1 | git status |
添加文件到暂存区
1 | git add <file> # 添加单个文件 |
提交更改
1 | git commit -m "描述本次更改" |
查看提交历史
1 | git log |
撤销修改
未使用 git add
1 | # 单个文件 |
已使用 git add, 未使用 git commit
1 | # 单个文件 |
已使用 git commit
1 | # 回退到上一次 commit 的状态 |
远程仓库
克隆远程仓库
1 | git clone https://github.com/username/repo.git |
添加远程仓库地址
1 | git remote add origin https://github.com/username/repo.git |
推送到远程仓库
- 首次推送
1 | git push -u origin main |
- 之后
1 | git push |
拉取远程更新
1 | git pull |
分支操作
查看分支
1 | # 查看所有分支 |
创建并切换分支
1 | git checkout -b new-branch-name |
切换分支
1 | git checkout branch-name |
合并分支
- 将 feature 合并到 main
1 | git checkout main |
删除分支
1 | git branch -d branch-name |
其它
查看差异
1 | git diff |