为了保持代码审查小而简洁,我提交了比完整功能更小的代码审查。这是较大更改之前的清理工作,但为了避免清理工作使最终审核变得困惑,我进行了此审核。
我以后的工作将建立在当前正在进行的审核的基础上,并且根据审核结果,我需要做出一些更改。不过,我还想在审查此代码期间继续开发最终功能。
如何正确跟踪我的功能开发,同时仍然能够进行代码审查更改。
当前情况:
master -x-x-x---x---|
feature \-x-x-x| code review
future 场景(分支)
master -x-x-x---x---|
feature \-x-x-x|-x--x--|
feature2 \x--x--x| code review complete (merge)
future 场景( stash )
master -x-x-x---x---|
feature \-x-x-x|-x--x--| code review complete (merge)
work on feature branch, stash changes if needed to make code review updates
我认为分支模型更有意义,但是创建另一个具有相同名称和相同目的的分支似乎违反了“git 规范”的某种意义
最佳答案
我认为分支是正确的方法;您可能只需要好的分支名称,而不是为您的工作创建一个新分支,而是使用新分支“卡住”代码快照以供代码审查。
当您想要提交功能
进行代码审查时,假设您的存储库如下所示。
* -- * -- * -- * -- * -- * -- * master
\
* -- * -- * -- * feature, HEAD
只需创建一个名为 (cr/feature
) 的新分支,其中 cr
是(您猜对了)“代码审查”的缩写。
git branch cr/feature
现在您当前的分支头有两个分支引用它。
* -- * -- * -- * -- * -- * -- * master
\
* -- * -- * -- * feature, cr/feature, HEAD
当您继续开发功能时,不会影响正在接受代码审查的代码。
* -- * -- * -- * -- * -- * -- * master
\
* -- * -- * -- * -- * -- * -- * feature, HEAD
|
cr/feature
代码审核完成后,审核后的代码是否会 merge 到 master
中?
git checkout master
git merge cr/feature
git branch -d cr/feature # Optional
* -- * -- * -- * -- * -- * -- * -- * master
\ /
* -- * -- * -- * -- * -- * -- * feature, HEAD
|
cr/feature (if not deleted)
这样,代码审阅者就永远不会看到您对功能
的持续工作,直到您通过显式创建分支供他们查看来提交代码 View 。
如果需要对已审核的代码进行更新,您可以将其添加到 cr/feature
分支:
* -- * -- * -- * -- * -- * -- * master
\
* -- * -- * -- * -- * -- * -- * feature, HEAD
\
* -- * cr/feature
并将 cr/feature
merge 回 feature
* -- * -- * -- * -- * -- * -- * master
\
* -- * -- * -- * -- * -- * -- * -- * feature, HEAD
\ /
* ----- * cr/feature
或在代码审查分支顶部重新设置功能
* -- * -- * -- * -- * -- * -- * master
\
* -- * -- * -- * * -- * -- * feature, HEAD
\ /
* -- * cr/feature
关于git - 在代码审查期间使用 git 跟踪更改(存储与分支),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30081136/