-1

I have a dozen feature branches that I would like to manually test at the same time by merging them into a single test branch, to avoid repeating the overhead of setting up the test environment for each feature branch. The branches have no merge conflicts because they don't touch the same parts of the code base.

While testing in this way, I might encounter a problem with one of the new features. I would like to be able to patch such a problem and continue testing. Then, when the testing is over, I would like to propagate those changes back to the relevant origin branches.

The impact of checking out the feature branch, patching it, then merging those changes back into the test branch, is significant enough that I hope to eliminate it from my workflow. Among other costs, it requires my IDE's language server to re-process the whole code base (~450k lines of C++) which means I lose those features for a significant amount of time each time I do this.

Does git have any commands, or are there any additional tools, that would enable this sort of workflow?

4
  • 2
    Wouldn't make it more sense to patch the issues in the original branch and merge these branches to your test branch again? Commented Aug 9 at 12:12
  • That adds a significant amount of time (multiple minutes) to the patching process, which I am trying to reduce or avoid. It adds up to hours over the course of a whole round of testing. Commented Aug 9 at 12:17
  • 2
    Please edit your question to include a detailed description why you can't fix the issue in the original branch and merge the changes then to your testing branch. It doesn't matter for the testing branch if the bugfix was written "directly" in the testing branch or if the bugfix was merged from the original branch. Commented Aug 9 at 12:43
  • I've added the requested information, although that seems very specific to my personal situation and not especially relevant to the more general question. Commented Aug 9 at 21:05

1 Answer 1

2

There is no easy to use feature in Git that would permit the proposed workflow. Since it was also a pain-point for me, I have implemented the command git post, the opposite of git cherry-pick.

You find its implementation in my Github repository. You can just extract the file git-post.sh (raw version) and place it such that PATH lookup finds it under the name git-post. Don't forget to make the file executable.

You use it like this (documentation):

git merge feature
# test, test, test; oops, here's a bug
# fix bug
git add -u
git commit   # provide message
git post feature

In this case, the top-most commit is replicated on top of branch feature and advances the branch to the replicated commit.

If you make multiple commits that belong to different topic branches feature-A, feature-B and feature-C (in this order) you can do

git post feature-A HEAD~2
git post feature-B HEAD~1
git post feature-C

This implementation of git-post requires that the replication on the feature branch is possible without merge conflicts.

Sign up to request clarification or add additional context in comments.

9 Comments

Does that just create new commits in the other branch? If yes, what's the difference from just cherry-picking instead? In addition to that, can you please elaborate on what exactly that does and how it works?
@dan1st git post takes the changes in the commit specified by the second argument (HEAD if not given) and creates a new commit whose parent is the given branch, and also advances the branch to point to the created commit. It is somewhat similar to git cherry-pick, but it operates in the opposite direction: git cherry-pick takes the commit there and puts it here; git post takes a commit here and puts it there. In particular, it advances a branch without checking it out.
So git post XYZ is the same as ref="$(git rev-parse --abbrev-ref HEAD)" && git checkout XYZ && git cherry-pick "$ref" && git checkout "$ref" while git post ABC XYZ is the same as ref="$(git rev-parse --abbrev-ref HEAD)" && git checkout XYZ && git cherry-pick "XYZ" && git checkout "$ref" (except maybe that it doesn't need to temporarily change the working tree)?
@dan1st Your first example is correct, the second should be ... && git checkout ABC && git cherry-pick XYZ && .... Except, of course, that git post doesn't do the checkout dance, so "is the same as" is not correct, but "has an effect comparable to" would be more correct.
yeah that was a typo - so is there a reason to use a custom command doing quite a bit of other logic instead of just checkout+cherry-pick (if necessary in a (non-git) alias or git- script). Doing all of these things just to skip the checkouts seems like a bit of unnecessary overhead.
@dan1st Yes there is: It doesn't do the checkout. Therefore, no rebuild is triggered when you are back at the branch where you started.
Also wouldn't creating commits like that (either with git cherry-pick or your custom script) result in having two commits with the same contents and different commit hashes (in the same history if you eventually merge them)?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.