[英]How can I implement this Git testing workflow
I have some features that were added to a product that reveal diagnostic information. 我有一些功能被添加到产品中,以显示诊断信息。 Because this information should not be revealed in production the branch is a few commits on top of master. 因为这些信息不应该在生产中显示,所以分支是在master之上的一些提交。
A-B-C-D-E (master)
\
F-G (local_testing)
Commits F
and G
make testing locally a lot easier. 提交F
和G
使本地测试更容易。 Now to add a feature and ensure it's working I check out a new branch new_feature
based on local_testing
. 现在添加一个功能并确保它正常工作我new_feature
根据local_testing
检查一个新的分支new_feature
。
git checkout -b new_feature local_testing
# Do work
git commit -a -m "H"
Commit H
adds the needed functionality. Commit H
添加了所需的功能。
A-B-C-D-E (master)
\
F-G (local_testing)
\
H (new_feature)
I have been interactively rebasing to move commit H
before commit F
. 我一直在交互式地重新定位以在提交F
之前移动提交H
Then I do a hard reset to move the commit object to which new_feature
points to the new H'
. 然后我进行硬重置以将new_feature
指向的提交对象移动到新的H'
。
git rebase -i master
git reset --hard H
So the commit history looks like: 因此提交历史记录如下:
A-B-C-D-E (master)
\
H' (new_feature)
\
F'-G' (local_testing)
Then I fast-forward master
to new_feature
and delete new_feature
. 然后我将master
快速转发到new_feature
并删除new_feature
。
git checkout master
git merge new_feature
git branch -d new_feature
This feels a bit clunky (particularly the hard reset). 这感觉有点笨重(特别是硬重置)。 Is there a better way to implement this flow? 有没有更好的方法来实现这个流程?
One solution would be to use git cherry-pick . 一种解决方案是使用git cherry-pick 。 You can from the branch master directly apply the commit H. 您可以从分支主机直接应用提交H.
git cherry-pick <H>
If you have multiple new commits, you can squash them with git rebase . 如果你有多个新提交,你可以用git rebase压缩它们。 You can also use multiple time the git cherry-pick
command. 你也可以多次使用git cherry-pick
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.