Re: The case for two trees in a commit ("How to make rebase less modal")
- Date: Thu, 1 Mar 2018 11:05:07 -0800
- From: Jonathan Nieder <jrnieder@xxxxxxxxx>
- Subject: Re: The case for two trees in a commit ("How to make rebase less modal")
Stefan Beller wrote:
> $ git hash-object --stdin -w -t commit <<EOF
> tree c70b4a33a0089f15eb3b38092832388d75293e86
> parent 105d5b91138ced892765a84e771a061ede8d63b8
> author Stefan Beller <sbeller@xxxxxxxxxx> 1519859216 -0800
> committer Stefan Beller <sbeller@xxxxxxxxxx> 1519859216 -0800
> tree 5495266479afc9a4bd9560e9feac465ed43fa63a
> test commit
> $ git fsck |grep 19abfc3bf1c5d782045acf23abdf7eed81e16669
> So it is technically possible to create a commit with two tree entries
> and fsck is not complaining.
As others mentioned, this is essentially a fancy way to experiment
with adding a new header (with the same name as an existing header) to
a commit. It is kind of a scary thing to do because anyone trying to
parse commits, including old versions of git, is likely to get
confused by the multiple trees. It doesn't affect the reachability
calculation in the way that it should so this ends up being something
that should be straightforward to do with a message in the commit body
To affect reachability, you could use multiple parent lines instead.
You'd need synthetic commits to hang the trees on. This is similar to
how "git stash" stores the index state.
In other words, I think what you are trying to do is feasible, but not
in the exact way you described.
> * porcelain to modify the repo "at larger scale", such as rebase,
> cherrypicking, reverting
> involving more than 1 commit.
> These large scale operations involving multiple commits however
> are all modal in its nature. Before doing anything else, you have to
> finish or abort the rebase or you need expert knowledge how to
> go otherwise.
> During the rebase there might be a hard to resolve conflict, which
> you may not want to resolve right now, but defer to later. Deferring a
> conflict is currently impossible, because precisely one tree is recorded.
Junio mentions you'd want to record:
- stages of the index, to re-create a conflicted index
- working tree files, with conflict markers
In addition you may also want to record:
- state (todo list) from .git/rebase-merge, to allow picking up where
you left off in such a larger operation
- similar state for other commands --- e.g. MERGE_MSG
Recording this work-in-progress state is in the spirit of "git stash"
does. People also sometimes like to record their state in progress with
a "wip commit" at the tip of a branch. Both of those workflows would
benefit from something like this, I'd think.
So I kind of like this. Maybe a "git save-wip" command that is like
"git stash" but records state to the current branch? And similarly
improving "git stash" to record the same richer state.
And in the spirit of "git stash" I think it is possible without
even modifying the commit object format.
> I'd be advocating for having multiple trees in a commit
> possible locally; it might be a bad idea to publish such trees.
I think such "WIP state" may also be useful for publishing, to allow
collaborating on a thorny rebase or merge.
Thanks and hope that helps,