Recovering "old commits" from multiple git lookups

I know this question, but am not sure how to match it with my current situation. (Rebase is scary, canceling rebase is doubly scary!)

I started with several different branches of my wizard's functions:

master xxxxxxxxxx \ \ \ FeatureA 1-2-3 \ \ FeatureB AB \ FeatureC XYZ 

I wanted to combine them all together and verify that they worked before merging back to the top of the wizard, so I did:

 git checkout FeatureB git rebase FeatureA git mergetool //etc git rebase --continue 

Then

 git checkout FeatureC git rebase FeatureB git mergetool //hack hack git rebase --continue 

What leaves me with

 master xxxxxxxxxx \ FeatureA 1-2-3 \ FeatureB A'-B' \ FeatureC X'-Y'-Z' 

Then I fixed some bits that did not compile properly and set the entire set of functions to an acceptable state:

 master xxxxxxxxxx \ FeatureA 1-2-3 \ FeatureB A'-B' \ FeatureC X'-Y'-Z'-W 

My problem is that my colleagues tell me that we are not ready for FeatureA.

Is there a way to save all my work, but also return to a situation where I can just reinstall FeatureC on Feature B?

+4
source share
3 answers

This is my understanding that the answer is based on comments:

When you do rebase, the commits on your current branch are “canceled” and then “reloaded”, but they are not actually canceled, they are “remembered” * and reused with new identifiers, for example, if I look in git reflog show FeatureB , I get something like this:

 7832f89 FeatureB@ {0} rebase finished: refs/heads/FeatureB onto f4df3 efd3fed FeatureB@ {1} commit: B f3f3d43 FeatureB@ {2} commit: A 2f32fed FeatureB@ {3} branch: Created from HEAD 

So, as @Jefromi said, the originals still exist (SHAs from A and B do not do the same thing in reflog as in git log, which correspond to A 'and B').

Similarly, git reflog show FeatureC as follows

 32873ef FeatureC@ {0} commit: W 17dafb3 FeatureC@ {1} rebase finished: refs/heads/FeatureC onto 89289fe 893eb78 FeatureC@ {2} commit: Z a78b873 FeatureC@ {3} commit: Y e78b873 FeatureC@ {4} commit: X 378cbe3 FeatureC@ {5} branch: Created from HEAD 

Again, the original Z, Y, and X are fixed, still exist

So, the solution to my problem is to create a new FeatureBC branch for the HEAD master (for example), then cherry-select commit FeatureB {2 and 1}, and then FeatureC {4, 3, 2} and (possibly) W:

 git checkout master git checkout -b FeaturesBC git cherry-pick f3f3d43 git cherry-pick efd3fed //etc... 

(It seems to have worked, I had to repeat some of the same mergers, but it was not so bad)

Edit, from Jefromi:

Cherry picking may not have been necessary. You can also simply recreate the branches where the branches were before the reboot:

 git branch FeatureB-old efd3fed git branch FeatureC-old 893eb78 

Or, if you want to throw away the changed FeatureB and FeatureC position, go back to where they were before:

 git branch -f FeatureB efd3fed git branch -f FeatureC 893eb78 

Finally, note that if you like, you can use another notation presented in the logs - for example, FeatureC@ {2} instead of 893eb78 . This means "second previous FeatureC position." Be careful to use this immediately after viewing the reflog, though, since as soon as you update the branch again (move it, lock it ...), FeatureC@ {2} instead refer to 17dafb3.

As @Jefromi commented on my question:

You probably created a new branch of the wizard or featureC (called ABC functions, say) and merged them into it, leaving the function branches intact. It’s good to keep an independent history of the various function branches.

<sub> * To be precise, old commit objects are simply left in the repository. They will eventually be truncated, since you do not want a repo full of old ragged commits; this will happen the first time git gc is running, and gc.pruneExpire for at least two weeks (with gc.pruneExpire configured). Sub>

+4
source

If all else fails, you can restart the wizard and git cherry-pick all B or C commit to recreate these branches. I hope someone else wrote a script if this is the only solution ...

0
source

you can use git rebase --onto <old-merge-base from B> AC to reinstall everything from C to A to the point on master. he will leave you with:

 master xxxxxxxxxx \ \ FeatureA 1-2-3 \ \ FeatureB A'-B' \ FeatureC X'-Y'-Z'-W 

to find the point you want to reinstall to, you can use a combination of git reflog and git merge-base - but you can also reinstall to merge base A to have a history similar to the following:

 master xxxxxxxxxx |\ FeatureA | 1-2-3 \ FeatureB A'-B' \ FeatureC X'-Y'-Z'-W 

( git rebase --onto $(git merge-base A master) AC )

0
source

Source: https://habr.com/ru/post/1307670/


All Articles