Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a git history as such:

* aab941c (HEAD -> master) Added ...
| * 2519b79 (participantQueue) Added ...
| * 39c4efb Created ...
|/  
* 87b0cf7 Import ...
| * 5569822 (settings) Modified ...
|/  
* ee67831 Added ...
* c07902f Added ...
* 7f5ab04 Added ...
* 82be721 Modified from `A` to `B`
* d86702b Modified from `A` to `B`
* 8cad721 Modified from `A` to `B`
* 5db240b Removing ...

I want to squash 8cad721 to 82be721, and end up with:

* aab941c (HEAD -> master) Added ...
| * 2519b79 (participantQueue) Added ...
| * 39c4efb Created ...
|/  
* 87b0cf7 Import ...
| * 5569822 (settings) Modified ...
|/  
* ee67831 Added ...
* c07902f Added ...
* 7f5ab04 Added ...
* 82be721 Modified from `A` to `B` (82be721, d86702b squashed into here)
* 5db240b Removing ...

I have tried git rebase -i 5db240b as suggested in other SO answers, replacing pick to squash for d86702b and 82be721. This results in the following:

* 4d91ea0 (HEAD -> master) Added ...
* 7040d3c Import ...
* f6c0fb5 Added ...
* 299c918 Added ...
* 58b209f Added ...
* e8b36f7 Modified from `A` to `B`
| * 2519b79 (participantQueue) Added default participant properties to unpaired queue export
| * 39c4efb Created ...
| * 87b0cf7 Import ...
| | * 5569822 (settings) Modified ...
| |/  
| * ee67831 Added ...
| * c07902f Added ...
| * 7f5ab04 Added ...
| * 82be721 Modified from `A` to `B`
| * d86702b Modified from `A` to `B`
| * 8cad721 Modified from `A` to `B`
|/  
* 5db240b Removing ...

What command should I be using instead?


After implementing the below answer by LeGEC, I have the following:

* 669164c (participantQueue) Added ...
* 5bc13a8 Created ...
| * 6abf940 (settings) Modified ...
| | * 3518be1 (HEAD -> master) Added ...
| |/  
|/|   
* | 2692632 Import ...
|/  
* 810389b Added ...
* 0c85217 Added ...
* 9284cff Added ...
* eee5eef Modified  from `A` to `B`
* 5db240b Removing ...

This threw me for a second as it does look different, but one more commit to master reorders the "trunk" of the git log output as before.

question from:https://stackoverflow.com/questions/65906355/squashing-past-git-commits

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
462 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to also rewrite the history of participantQueue and settings, so that they fork off the new commits you created for master.

You can use git rebase --onto ... :

# for 'settings' :
git checkout settings
# rewrite onto f6c0fb5 the history coming after ee67831 :
git rebase --onto f6c0fb5 ee67831

# for 'participantQueue' :
git checkout participantQueue
# rewrite onto 7040d3c the history coming after 87b0cf7 :
git rebase --onto 7040d3c 87b0cf7

If you had a bigger set of branches or tags to move, you would be better off using a global rewriting tool, such as git filter-repo.

In your case, with only two extra branches to move, this more manual way will work just as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...