Nikolay Shustov [off-list ref] writes:
I am not really try to ignite the holy war between Perforce and Git
(and why would one???), but if you are interested in the answer on how
you'd do your scenario in Perforce, it would be: "use shelved
changelists".
Oh, that was not my intention, either. My interest was to see if
there is a good solution that we could steal from other world.
In Perforce, you could "shelve" the changelist, similar to "stash" in
Git, but the difference is that the Perforce shelved changes are
accessible across clients. I.e. the other developer can "unshelve"
these pending changes to its sandbox (to the same or the different
branch) so that sandbox would get the pending changes as well. That
would be like the developer made these changes himself. Whatever
automated/manual process is involved, it is typical to run "a trial
build/tests" on shelved changelist (i.e. uncommitted yet files) to
verify the quality of changes.
Git achieves the same through the ease of manipulation with branches
and I like the way it does it much more.
Thanks. Shelving and letting others unshelve is like keeping the
changes in separate branches and privately share them among
developers, so they sound pretty much equivalent features to me.
My question was about how to robustly handle "multiple pending
commits" which in Perforce are represented by concept of pending
changelists.
And in Git, they are represented by concept of commits that are not
yet pushed out to the public repository to become the final history
carved in stone.
On 13/07/2017 23:20, Junio C Hamano wrote:
Nikolay Shustov [off-list ref] writes:
quoted
My question was about how to robustly handle "multiple pending
commits" which in Perforce are represented by concept of pending
changelists.
And in Git, they are represented by concept of commits that are not
yet pushed out to the public repository to become the final history
carved in stone.
If I may, I don`t think "multiple pending commits" is the issue here
(as that is indeed what a private branch is), but more something like
"multiple branches pending/live merge branch", or something.
To illustrate, let`s say this is our starting position:
(1) o---o---o (featureA)
/ \
---o---o---o---M (master, HEAD)
\ /
o---o---o (featureB)
We`re currently on commit "M", being a merge commit between our
"master" and two feature branches.
Now, what seems lacking, while still possible through a series of
steps, is an easy (single step) way to modify current state and
commit the change to the _feature branch_, while still being on the
"master" branch, still having everything merged in.
So after I make a "featureA" related change while on "M", to be able
to issue a single command, for example:
$ git commit --branch=featureA
... or:
$ git commit -b featureA
..., where "featureA" would need to be one of the parents of the
current commit we are at (commit "M", in our case), and get a
situation like this:
(2) o---o---o---A (featureA)
/ \
---o---o---o-------M' (master, HEAD)
\ /
o---o---o---/ (featureB)
Here, "A" is a new commit/change I`ve just made (while still being on
the "master" branch), and it is automatically commited to related
"featureA" branch, with merge commit "M" now recreated into "M'" to
hold the new "featureA" commit "A" as well.
I guess it would be a kind of alias to doing:
$ git checkout featureA
$ git add ...
$ git commit
$ git checkout master
$ git reset --hard HEAD^
$ git merge featureA featureB
... or something, where last merge step would need to remember
previous merge commit "M" parent branches and merge them again to
produce an updated "M'" merge commit.
In the same manner, it should be possible to drop a commit from the
feature branch in a single step, for example returning to the state
as shown in (1), or even "port" it from one branch to the other, like
this (without a need for it to be the last commit, even):
(3) o---o---o---\ (featureA)
/ \
---o---o---o-------M' (master, HEAD)
\ /
o---o---A'--o (featureB)
Something like "rebase on steroids", lol, keeping the HEAD where it
is, and its merge commit beneath updated.
This indeed seems similar to Mercurial`s patch "queues", except being
much better as everything is still version controlled at all times,
no additional tools needed to version control the patches (unless
that`s already been addressed in Mercurial as well, dunno).
And it still seems to be following Git`s "multiple commits per
feature, single feature per branch" spirit, just allowing for
easier/faster branch integration testing.
p.s. Even if my short sample might be flawed in one way or the other,
it should show the essence of the functionality we`re discussing
here, I think.
Regards,
Buga
Just a small update/fixup:
On 14/07/2017 00:39, Igor Djordjevic wrote:
I guess it would be a kind of alias to doing:
$ git checkout featureA
$ git add ...
$ git commit
$ git checkout master
$ git reset --hard HEAD^
$ git merge featureA featureB
This should, in fact, be:
$ git checkout featureA
$ git commit
$ git checkout master
$ git reset --hard HEAD^
$ git merge <HEAD@{1} parents>
(removed "git add" step, as that is needed for proposed single step
solution as well, as a usual step preceding the commit; also replaced
concrete branch names in the last step with a more generic
description, better communicating real intent)
In the same manner, it should be possible to drop a commit from the
feature branch in a single step, for example returning to the state
as shown in (1), or even "port" it from one branch to the other, like
this (without a need for it to be the last commit, even):
(3) o---o---o---\ (featureA)
/ \
---o---o---o-------M' (master, HEAD)
\ /
o---o---A'--o (featureB)
Here, the diagram should look like this:
(3) o---o---o---\ (featureA)
/ \
---o---o---o-------M'' (master, HEAD)
\ /
o---o---A''-o (featureB)
(replaced leftover M' from the previous diagram with M'' to show it`s
yet another (updated) merge commit, different from both M and M' in
terms of SHA1, yet the contents would probably, but not necessarily,
be the same for all three; same for leftover A', replaced with A'')
Regards,
Buga
Eh, yet another one, sorry:
On 14/07/2017 01:32, Igor Djordjevic wrote:
$ git checkout featureA
$ git commit
$ git checkout master
$ git reset --hard HEAD^
$ git merge <HEAD@{1} parents>
The last line should stress <HEAD@{1} *parent branches*>, as we`re
not merging exact parent commits the previous merge commit was made
of, but updated tips of the branches the previous merge commit was
made of... or something along those lines :)