1.git 工作区介绍
区域介绍
流程
2.一般使用流程
1. git clone url // 从url clone最新代码
2.git checkout -b mybranch // 新建分支并且换到mybranch,然后在mybranch上开发代码
3.git status // 查看代码状态
4.git add . // 将工作区代码加到暂存区(有时需要一个个添加 git add filename )
5.git commit // 将暂存区代码添加到本地仓库,需要添加详细注释(git commit -m "注释")
6.git review // 将本地库代码同步到远程仓库 类似于 git push
3.异常处理
# 当在自己的分支上开发完成之后,需要提交代码
1. git status // 查看代码修改状态
2.git add . // 将代码从工作区添加到暂存区
3.git commit // 将代码从暂存区,添加到本地仓库,并添加详细注释
4.git checkout master // 切换到主分支
5.git pull // 拉取主分支最新代码
6.git checkout mybranch // 切换到自己的代码分支
7.git rebase master // 同步master代码 (自行了解rebase作用)
8. 如果有冲突,解决冲突
9.git add * // add完 不需要commit(切记)
10.git rebase --continue
11.git review // 提交到远程仓库
(git rebase 和 git merge 的区别自行了解)
4.其他命令
git log // 查看commit日志(重要)
git reflog // 查看详细操作日志(重要)
git branch // 查看分支
git branch [mybranch-name] // 新建分支 mybranch
git checkout [mybranch-name] //切换到 mybranch 分支
git branch -m oldbranch newbranch // 修改分支名称
git reset [ID] // 回到某个节点(一般使用以下形式)
git reset --soft HEAD^ // 不删除工作空间改动的代码,撤销 commit,不撤销 git add . (git reset ID --soft HEAD^)
git reset --hard HEAD^ // 删除工作空间改动代码,撤销 commit,撤销 git add . 注意:完成这个操作后,就恢复到了上一次的commit状态
git reset --mixed HEAD^ // 等同于默认 git reset HEAD^ 效果自己体会
#(不删除工作空间改动代码,撤销commit,并且撤销git add . 操作
# 这个为默认操作 git reset --mixed HEAD^ 和 git reset HEAD^ 效果是一样的)
# 从正在开发的分支切换到其他分支不能直接切换,需要保存工作区内容
git stash // 保存工作区的内容(进度),再运行 git status 就是干净的工作区,git stash save 'message...' 可以添加一些注释
git stash list // 显示保存进度的列表
git stash pop [–index] [stash_id]
git stash pop 恢复最新的进度到工作区
git stash pop --index 恢复最新的进度到工作区和暂存区
git stash pop stash@{1} 恢复指定的进度到工作区。stash_id是通过git stash list命令得到的
git stash apply [–index] [stash_id] //除了不删除恢复的进度之外,其余和git stash pop 命令一样
git stash drop [stash_id] // 删除一个存储的进度。如果不指定stash_id,则默认删除最新的存储进度
git stash clear // 删除所有存储的进度
git branch --set-upstream-to=origin/<branch> mybranch // 将本地分支关联到远程分支
gerrit 提交代码没有出现代码层面问题但是 -1,使用replay -> recheck->send 重新检查(备注)