Re: Merging commits together into a super-commit
From: Carl Worth <hidden>
Date: 2016-06-15 22:43:09
On Thu, 10 May 2007 13:14:57 -0400, "J. Bruce Fields" wrote:
I use it all the time to fix up old commits with git checkout sha1-of-bad-commit ...edit, test,... git commit -a ---amend git rebase --onto HEAD sha1-of-bad-commit original-branch
Excellent. Thanks for the description.
Fixing up some broken (unpublished) commit in the past is a useful
thing to support[*]. Of course, "commit --amend" takes care of this for
the case where it's the most recent commit. For an older commit, here
is exactly what I'd like to do, (showing that my suggestion of
cherry-pick with a range would cover exactly this scenario):
git tag tainted # Could be "git branch tainted" just as well
git reset --hard bad-commit
...edit, test...
git commit --amend
git cherry-pick bad-commit..tainted
git tag -d tainted
So, compared to the rebase usage, this does add two commands for
bookkeeping the original state and cleaning it up. But the syntax for
the cherry-pick part is quite a bit simpler than the original rebase
at least.
Also, "reset --hard" isn't actually what I want in this case. I'd like
this recipe to use something that would move the current branch to
some other point, but in a safe way, (that is, not destroy any
uncommitted changes that might exist at the beginning). I don't have
any proposal for what that would be.
-Carl
[*] I've also experimented with using other "non-core git" ways of
addressing this same problem. Here are a couple that I haven't found
satisfactory for this particular use case:
stg - This probably works great if you're using it as a primary
interface. But trying to use it as a quick one-off when
generally using core git does not work well at all. Instead of
the two "git tag" commands in my recipe above, an stg recipe
would involve a lot of additional bookkeeping with stg init, stg
uncommit [N times for fixing a commit N steps back in the
history], stg goto, stg push, etc.
cg-admin-rewritehist - This is a powerful tool, but its interface
isn't geared toward interactively fixing things up, (instead
requiring a filter to be executed at all steps). So, while it's
great for changing history, (as its name suggests), such as
performing a sed operation on the commit messages, or
eliminating a file, it doesn't help much with the "fix up one
broken commit in the past".
It is worth noting that quite unlike rebase,
cg-admin-rewritehist can deal quite nicely with history that
involves branching and merging.
Attachments
- (unnamed) [application/pgp-signature] 189 bytes