Git记录
# Git基础使用
# git基本提交流程
git init
- 创建新的git仓库
git clone
- 克隆仓库
git
工作流- 本地git仓库由git维护的三棵树组成, 第一个是工作目录,持有实际文件,第二个是缓存区,用来临时保存改动,第三个是HEAD指向最后一次提交结果
git add filename
- 将改动添加到暂存区 如果全部添加使用
git add .
- 将改动添加到暂存区 如果全部添加使用
git commit -m[message]
- git commit 命令将暂存区内容添加到本地仓库中。
- 使用git commit -a可以直接跳过git add直接提交代码
- 这时改动已经提交到了HEAD 但是没有提交到远程
git push
# 各种场景下指令
git reset --soft HEAD^
- 用于撤销commit
- 参数的意思是
- --soft :不删除工作空间改动代码,撤销commit,不撤销git add .
- --mixed:不删除工作空间改动代码,撤销commit,并且撤销git add . 操作
- --hard:删除工作空间改动代码,撤销commit,撤销git add .
- HEAD^的意思是上一个版本,也可以写成HEAD~1
git stash
- 用于暂存代码
git stash apply
- 从暂存栈中取出提交 但不从栈中删除
git stash pop
- 从暂存栈中取出提交 会从栈中删除
git merge branch
产生新的提交信息
# --no-ff 即 no-fast-forward 禁用快进模式
$ git merge hotfix --no-ff
1
2
2
编辑 (opens new window)
上次更新: 2023/02/02, 18:26:04