- git init : 初始化仓库
- git clone : 克隆一个已存在的仓库
git clone <仓库链接>
- git add : 将修改的文件添加到暂存区
git add file1.txt
git add . # 把所有文件添加到暂存区
- git commit : 创建一个新的提交
git commit -m "添加新功能"
- git push : 将提交推送到远程仓库
git push origin <要推送的仓库分支名称,例如develop>
- git pull : 从远程仓库获取并合并修改
git pull origin <要拉取的仓库分支名称,例如develop>
- git branch : 列出、创建或删除分支
git branch # 查看所有分支
git branch <分支名称> # 创建新的分支
git branch -d <分支名称> # 删除分支
- git checkout : 切换分支
git checkout <要切换到的分支名称>
- git merge : 合并分支
# 例如 git merge develop :将develop的更改合并到当前分支
git merge <branch-name>
- git status : 显示仓库状态
git status
- git rebase : 将一个分支的修改提交合并到另一个分支
git rebase <branch-name>
- git stash : 临时保存还未准备提交的修改
git stash save "message" # 用message表示stash
git stash apply # 将最近的stash应用到当前分支
git stash pop # 恢复并移除最近的stash
git stash list # 列出所有保存的stash
- git revert : 撤销之前的提交
git revert <commit> # commit 要撤销的提交的哈希值或引用