Serob_b
Serob_b

Reputation: 1059

Git rebase - i squashing didn't remove commit

I have a local commit after origin master's head, and want to combine last two commits. So suppose the history is as follows:

* e9199ba - (HEAD -> master)
|           test
* c4e3b53 - (origin/master, origin/HEAD)
|           Saturn ring angle change in X and Y

And want to make one commit instead of e9199ba and c4e3b53. I did git git rebase -i HEAD~2 and squashed the second commit:

pick c4e3b53 Saturn ring angle change in X and Y
squash e9199ba test

As a result I've got two independent commits - the new squashed one and old master's one:

* 216b314 - (HEAD -> master)
|           Suqashed commits
| * c4e3b53 - (origin/master, origin/HEAD)
|/            Saturn ring angle change in X and Y

What's wrong here? Is it by the reason of the origin master's head? How to combine them in this case? Or maybe there is some history showing issue?

Upvotes: 0

Views: 1128

Answers (1)

torek
torek

Reputation: 487993

Just as you said:

... I've got two independent commits - the new squashed one and old master's one

which is what you should expect, since git rebase works by copying commits (perhaps with some modifications along the way, such as squashing), then having your Git point your own branch name to the new copies.

But origin/master is not your own, rebased, branch. It's your remote-tracking branch, and it remembers what some other Git has in that other Git's master. Hence your origin/master continues to remember what that other Git has, which is the original commits before you made slightly-modified copies.

That other Git repository itself—the one you call origin—has the other commit. Since origin has it, anyone who has copied from origin also has it. You must convince origin, and anyone who has copied from origin, to switch over to your shiny new commits.

If you have control over origin, you can likely use a "force push" to overwrite whatever it has now in its master with your shiny new commits. (The origin repository will still have the old commit too, though perhaps very briefly until it does a "garbage collection" pass.) Then you must also convince all users of origin to switch, too, just like you did and just like you forced origin to do. Exactly how you can and will do that is up to you.

Note that if other people are also pushing to origin, it's possible that your force-push will wipe away commits they have added, that depend on c4e3b53. You should coordinate with these other people before force-pushing. (If there are no such other people, that makes the coordination a lot easier.)

Upvotes: 3

Related Questions