Syl
Syl

Reputation: 21

How to Git rebase with only one "verification"


Hello ! everyone I need help please... I have :

I want squash all my old commit with rebase But my branch is very old... and i have lot of useless commit. and when i do

$ .../.../..(mybranch-actually): git rebase -i origin/master

it makes me a difference check for each commit (old-1, old-2, old-3).
But is it's useless, I would like him to check only my most recent commit (old-1 with master) and ** directly squash all other commit in mybranch-actually** without verification

Upvotes: 1

Views: 146

Answers (1)

matt
matt

Reputation: 535556

As I understand it, you want to keep old-1 as a separate commit, but squash everything from old-2 back to some starting point into a single commit. And you don't want to bother with an interactive rebase to do it.

I'm sure there are clever ways to do that, but here's a simple recipe. I'll start with this situation:

* 699abbb (HEAD -> actual) e
* 6c924b6 d
* 51c7c64 c
* 2f15c0c b
* ae36341 a
| * c785b2c (main) second
|/  
* e77cdf8 start

My goal is to keep e but turn a, b, c and d into a single commit, which I'll call squash. Here we go. Notice that I am actually on actual to begin with:

git switch -c temp HEAD~1
git reset --soft e77cdf8
git commit -msquash

We now have this:

* 56d04c1 (HEAD -> temp) squash
| * 699abbb (actual) e
| * 6c924b6 d
| * 51c7c64 c
| * 2f15c0c b
| * ae36341 a
|/  
| * c785b2c (main) second
|/  
* e77cdf8 start

This may not look like any improvement, but in fact squash is the same as a and b and c and d squashed together. So all we need to do is throw them away and stick e on the end of temp, right after squash. Okay then:

git switch actual
git rebase --onto temp actual~1 actual
git branch -d temp

And now we have this:

* f259d42 (HEAD -> actual) e
* 56d04c1 squash
| * c785b2c (main) second
|/  
* e77cdf8 start

Since squash is, as I have said, a summation of the old a and b and c and d, this is exactly what you were looking for. Now if you want to do more with actual, you can do so, but the branch history looks the way you want it.

Upvotes: 2

Related Questions