简体   繁体   中英

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.

A-B-C-D-E (master)
         \
          F-G (local_testing)

Commits F and G make testing locally a lot easier. Now to add a feature and ensure it's working I check out a new branch new_feature based on local_testing .

git checkout -b new_feature local_testing
# Do work
git commit -a -m "H"

Commit H adds the needed functionality.

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 . Then I do a hard reset to move the commit object to which new_feature points to the new 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 .

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 . You can from the branch master directly apply the commit H.

git cherry-pick <H>

If you have multiple new commits, you can squash them with git rebase . You can also use multiple time the git cherry-pick command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM