admin管理员组文章数量:1406924
Project sources have multiple conditionals that used to only test many different scenarios, but such logic should never slip to production-ready state of the code (it's a requirement).
Thus, when I need to develop new "feature", I take "production", apply "test" changes on top of it, implement the "feature" by typing in the new logic and when tests pass (some auto, some manual), remove "test" changes and then commit "feature" to "production".
Are there any Git practices that might assist in that?
Everything I've tried: worktree
, git merge --no-commit
, patch
.
Project sources have multiple conditionals that used to only test many different scenarios, but such logic should never slip to production-ready state of the code (it's a requirement).
Thus, when I need to develop new "feature", I take "production", apply "test" changes on top of it, implement the "feature" by typing in the new logic and when tests pass (some auto, some manual), remove "test" changes and then commit "feature" to "production".
Are there any Git practices that might assist in that?
Everything I've tried: worktree
, git merge --no-commit
, patch
.
1 Answer
Reset to default 1I'm not quiet sure I understand your question correctly. But if I do you should be able to utilize git rebase
for this.
So, if I understand correctly you want to track some code for testing that should never be included in the branch which is used for production. While developing a new feature you need that code to be present but when merging the new feature to the production branch it should not include the (commits with) test code.
For this you would need three branches:
production
holding the code to be deployed to productiontests
consisting of the same code asproduction
+ the additional test codefeature
consisting ofproduction
+tests
+ new commits for the new feature
In the beginning these branches can simply build on top of each other:
o---o---o <-- production
\
T1---T2---T3 <-- tests
\
F1---F2---F3 <-- feature1
Where the commits T1-T3 introduce the test code you don't want to be part of production
. When starting a new feature branch feature1
it is first the same as tests
and then you add the commits F1-F3 for the new feature to it.
When you are done with development you can now rebase the commits of frature1
on top of tests
back on production
, see git rebase --onto
:
# while on branch feature1
git rebase tests --onto production
which will result in
o---o---o <-- production
|\
| F1'---F2'---F3' <-- feature1
\
T1---T2---T3 <-- tests
Now you can just merge/fast-forward production
to feature1
with
git checkout production
git merge feature1
which will result in
o---o---o---F1'---F2'---F3' <-- production, feature1
\
T1---T2---T3 <-- tests
So now you have all the new feature commits of feature1
included in production
but the commits T1-T3 are still in their own branch.
For the next feature you can then do the same with a new branch feature2
branching from tests
again. But first you need to include the new feature commits in tests
which you can either do with git rebase
tests
on production
or git merge prodcution
:
# on branch tests
git rebase production
which will result in
o---o---o---F1'---F2'---F3' <-- production
\
T1'---T2'---T3' <-- tests
\
F4---F5---F6 <-- feature2
or
# on branch tests
git merge production
which will result in
o---o---o---F1'---F2'---F3' <-- production, feature1
\ \
T1---T2---T3-----o <-- tests
\
F4---F5---F6 <-- feature2
本文标签: gitWhat39s the best way of keeping changes that should never move to main branchStack Overflow
版权声明:本文标题:git - What's the best way of keeping changes that should never move to main branch? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744973885a2635401.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
git cherry-pick --no-commit test
(if all your changes are in the last commit of this branch. If not, replacecherry-pick
withmerge
, the principle is the same), test what has to be tested, thengit cherry-pick --abort
? – Romain Valeri Commented Mar 6 at 13:45