I'm someone who's always constructing checkins of only a portion of the differences in my worktree, so some of git's special features — notably git add -i -p
and -e
— are a real boon. But as useful and as powerful as add -i -p
can be, I find myself wanting even more.
In a nutshell, I'm wondering if there's any way to cleanly and automatically exclude from the checkin any deltas which are already checked in under other branches. This need arises from at least two common-enough scenarios:
I've got some idiosyncratic or personal changes which I don't intend to check in to my project's main-line branches, because they'd be distracting and not useful to anyone else. I've probably checked them in to my own personal branch, but then cherry-picked them back into a branch I'm working on.
I'm working on a new feature, in a feature branch, but I need to test it along with some new code which a co-worker is simultaneously developing in his own feature branch. I can easily merge the co-worker's feature branch into mine, but when it comes time to check changes in to my feature branch, I want to check in only my feature's changes, not the co-worker's.
In either case, I could just use add -i -p
, and say "no" to all the changes I don't want to check in. But that gets tiresome if, checkin after checkin and day after day, I'm saying "yes" to only a handful of actual, new changes, and exhaustively saying "no" to rafts of the same changes I said "no" to on the previous checkin, and the one before that, and the one before that.
So, in a little more detail, what I'm looking for is a decently clean and easy way to do something like git add -i -p
, except that it automatically answers "no" to (and does not even show me) any patch hunk which is already exactly present on some other branch. I'd probably be fine with explicitly mentioning the name(s) of the other branch(es) whose changes I want to exclude. (Obviously there will occasionally be cases where nearby "old" and "new" changes get coalesced into a single hunk, which can't be automatically suppressed and which I'll therefore have to manually edit, and I'm fine with that.)
Does this make sense? Does anyone know of a good way to achieve this?