Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to bind commits to each other to make them atomic in terms of bisect, cherry-pick, revert, etc?

Tags:

git

workflow

Consider the case of a bug fix which causes a small change in the expected output, forcing a minor change in the test suite. It is extremely convenient to have both changes in the same commit, since it makes it obvious to the reviewer exactly what is changed in the output. On the other hand, sometimes you might just want to view the diffs to the source, or the diffs to the expected output and it is much easier to do that if the commits are separate. Also, the two things are logically distinct so it makes sense to make distinct commits.

I would love to be able to make two distinct commits, but somehow have the two commits linked together in some way (so that I can cherry-pick, revert, etc. both commits as an atomic unit). Also, if two distinct commits are made, then the test suite will fail on the first commit (unless a third commit is introduced to relax the test suite), making future bisects a pain. The issue of future bisects failing generally encourages me to make a single commit, but commits should be logically distinct units and a commit to code is logically distinct from a commit to the expected output in the test suite.

Is there a way to make two distinct commits and not have to bend over backwards to prevent bisect from failing on one of them? (eg, having to explicitly mention commits to skip)

like image 207
William Pursell Avatar asked Jun 03 '11 14:06

William Pursell


People also ask

How does cherry pick commit work?

Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.

How do you cherry pick a commit and merge to master?

Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. "Cherry pick" the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here . That will pull just this commit into your current branch.


1 Answers

Definitively keep those changes (code and unit test) as one commit: SCM is also about being able to reproduce a given state, and that include both the program and its tests.

If you need to review only code changes, do a git diff on src only, not on tst.
Since those linked changes remain in one commit, you avoid the bisect issue entirely.

In short, keep it simple ;)

like image 70
VonC Avatar answered Sep 28 '22 06:09

VonC