[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Help combining git branches [Was: valyuta/002 18ab8be 5/5: Oops]
From: |
Greg Chicares |
Subject: |
[lmi] Help combining git branches [Was: valyuta/002 18ab8be 5/5: Oops] |
Date: |
Tue, 29 Sep 2020 15:55:36 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 |
[...I say "combining" because "merge" is a technical term, and I suspect
that what I ideally want is techically a "rebase", but I'm not sure...]
On 2020-09-20 23:24, Vadim Zeitlin wrote:
> On Sun, 20 Sep 2020 22:37:51 +0000 Greg Chicares <gchicares@sbcglobal.net>
> wrote:
[...]
> GC> git branch odd/foo
> GC> git reset --keep origin/master
[...]
> GC> # ...and don't ever rebase that new branch
[...remove that "don't ever" comment?...]
> 1. Remove the comment: I think it's a bit too drastic, it might be useful
> to note that you shouldn't rebase this branch on master without using
> either an explicit branch name or --no-fork-point explicitly (you don't
> have to document both ways, just choose one you like best and it will
> be enough).
I just realized that I don't understand what you said. To rebase
branch A on branch B, I should think it's necessary to name them
both...so mustn't both branch names always be explicitly specified?
Anyway, accepting this invitation:
> But in the meanwhile, good luck and please let me know if you have any
> questions!
Would you mind looking over my virtual shoulder while I try to do
something that seems awfully basic in git, and letting me know what
you'd do instead? Here's the situation:
- I added branch valyuta/002;
- valyuta commits are carelessly casual; eventually, I'll want many
of their ultimate effects on master, but I'm sure I'll never want
their twisted history on master; and
- I've made changes there and to master, so they've diverged.
Now there are some commits on master that I want on the branch (for
pc-linux-gnu support). (There are also some commits on the branch that
represent pure improvements that have nothing to do with 'currency',
and I'd ideally like to perform on master, but that can wait.)
My first thought was to cherry-pick from each to the other, but I think
that's not a recommended technique for a complex long-lived branch like
valyuta/*, and I suspect it would make merging or rebasing harder, so I
figured this would be a good time to try a different approach.
The first thing I tried was:
$git switch valyuta/002
Switched to branch 'valyuta/002'
Your branch is up to date with 'origin/valyuta/002'.
$git rebase --no-fork-point master
Applying: Change type of currency variables to 'currency' in headers
Applying: Currency
Using index info to reconstruct a base tree...
M ihs_acctval.cpp
M ihs_avmly.cpp
M ihs_avsolve.cpp
Falling back to patching base and 3-way merge...
Auto-merging ihs_avsolve.cpp
CONFLICT (content): Merge conflict in ihs_avsolve.cpp
Auto-merging ihs_avmly.cpp
CONFLICT (content): Merge conflict in ihs_avmly.cpp
Auto-merging ihs_acctval.cpp
CONFLICT (content): Merge conflict in ihs_acctval.cpp
error: Failed to merge in the changes.
Patch failed at 0002 Currency
hint: Use 'git am --show-current-patch' to see the failed patch
...and already I'm in the Twilight Zone. The first of about forty
commits came through okay, but the second failed, and all I have to
work with is a monolithic patch file. Maybe I could handle that for
one commit, but not for forty, so I abort and try a different command:
$git rebase --abort
$git rebase master
But that has the same effect. (I guess that's because the
'--no-fork-point' option is implicit when I name master explicitly).
After aborting again, I try '--onto' because it sounds like it would
be perfect for my purposes, according to this diagram:
https://stackoverflow.com/questions/33942588/difference-between-rebase-master-and-rebase-onto-master-from-a-branch-deri/33942992#33942992
| After a standard rebase (without --onto master) the structure will be:
|
| o---o---o---o---o master
| | \
| | x'--x'--x'--x'--x'--o'--o'--o' B
| \
| x---x---x---x---x A
|
| ...where the x' are commits from the A branch. (Note how they're now
duplicated at the base of branch B.)
|
| Instead, a rebase with --onto master will create the following cleaner and
simpler structure:
|
| o---o---o---o---o master
| | \
| | o'--o'--o' B
| \
| x---x---x---x---x A
$git rebase --abort
$git rebase --onto master
First, rewinding head to replay your work on top of it...
I was surprised that it just stopped there, but I figure git-status
will tell me what work remains:
$git status
On branch valyuta/002
Your branch and 'origin/valyuta/002' have diverged,
and have 42 and 112 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
$git pull
fatal: Not possible to fast-forward, aborting.
Okay, no surprise there, so...
$git pull --no-ff
Auto-merging ihs_avsolve.cpp
CONFLICT (content): Merge conflict in ihs_avsolve.cpp
...
Automatic merge failed; fix conflicts and then commit the result.
This seems a lot better than editing git-am patches. I fix the
(very few, and minor) conflicts in 'vim' and forge ahead:
$git add gwc/develop1.txt ihs_avmly.cpp ihs_avsolve.cpp
$git status
On branch valyuta/002
Your branch and 'origin/valyuta/002' have diverged,
and have 42 and 112 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
I've already pulled, so now I'll commit:
[valyuta/002 abf690c4] Merge branch 'valyuta/002' of git://git.sv.gnu.org/lmi
into valyuta/002
And it looks like I'm all done:
$git status
On branch valyuta/002
Your branch is ahead of 'origin/valyuta/002' by 43 commits.
(use "git push" to publish your local commits)
But I want to understand what happened, and here I'm confused.
$git log --graph --oneline --all -200
I think it'll be clearest if I present extracted blocks of '--graph'
output in their original order. But that means I must ask you to skip
ahead to "rbegin()" below and read my interleaved annotations backward.
[this is the "rend()" of reverse-chronological '--graph' output]
Here's my burning question: dare I push this? If I do, might I destroy
valyuta/002 in some irrevertible way? Should I now do something like:
git switch --create valyuta/003
git reset --keep origin/master
git push --set-upstream origin valyuta/003
to keep valyuta/002 intact, in case I try working with whatever I've
just created and find that it's ruined? Well, let me do that anyway,
because it has to be safe, even if wasteful.
* abf690c4 (HEAD -> valyuta/002) Merge branch 'valyuta/002' of
git://git.sv.gnu.org/lmi into valyuta/002
|\
| * 5fb74f1b (origin/valyuta/002) Prefer cents() to m()
| * 89b2c7ab Fix incorrect documentation
| * 2f32980d Do away with unused return value #5
| * 94197291 Do away with unused return value #4
Here the flow marked with '|' crosses over, exactly at origin/master.
I guess that's because git wisely avoids rewriting a pushed master
branch.
| * 360060cb suppress failing assertions
| * 08560813 improve currency
* | f94663e9 (origin/master, origin/HEAD, master) Add a script that's not ready
to use
* | 3299d705 (xanadu/master) Sidestep a vim regression
I had switched back to master and done some work there.
* | b99f6ac4 Include all 'sample*' product files in a fardel by default
* | 5d8c62c8 Add another little git recipe
| | * ef5db171 (origin/odd/string_db, odd/string_db) Allow product lingo to
vary by state, gender, and so on
| |/
|/|
* | bddd7c3d Improve gcc warning options
* | f4d9e2e8 Restore last position in vim
* | 193164fb Improve a git-branch recipe
* | 6a05bcee Resolve a marked defect [338]
* | f7868401 Avoid catastrophic cancellation
* | 1a54e490 Clarify non-MEC solves
Here, I tried some ideas that weren't all good enough for valyuta/002,
so I stuffed them onto a new throwaway branch.
| | * 657673a0 (valyuta/002x) flailing
| | * 9913071e some good ideas here
| | * dfab1b3d round.c()
| | * 58acbbca round.c()
| | * b067f1cf round.c()
| | * 82c14bcb improve currency
| |/
| * 9bee994b use currency type
Okay, this is the original point where valyuta/002 came into existence.
I thought 'git rebase --onto master' was instead supposed to jump to
the HEAD of master and then replay all of valyuta/002's commits onto
it: isn't that what the diagram from stackoverflow above implies?
But whatever it's doing here looks good enough for my present goal.
| * ce34d890 improve
| * bf1943bb reformat
| * d137177b Currency
| * ef7fe2fc Change type of currency variables to 'currency' in headers
|/
* 59860e39 Move partial mortality into base class
[this is the "rbegin()" of reverse-chronological '--graph' output]