wei
wei

Reputation: 6919

GIT: how to squash several commits that have been pushed to a remote repo?

I have a weird setup with Git. Basically I have:

[client 1] <---> [remote repo] ----> [client 2]

[Client 1] is essentially the local repo I am working with, because I can't compile/build the project on my local machine.

[Client 2] is a remote server for building.

In the middle, I have another repo, [remote repo], basically for synchronizing with a cvs central repo in my company, and also synchronizing between my [client 1] and [client 2].

Since all the compiling/building is done on [client 2], I have many trivial commits on [client 1] just for fixing the compilation or building errors.

So by the time I find out there are errors in the last commit, it's already too late because the commit has already been pushed to and pulled from the remote repo.

How can I squash these (many) trivial commits into one? Thanks.

Upvotes: 16

Views: 32761

Answers (2)

manojlds
manojlds

Reputation: 301607

First of all, avoid squashing and in general rewriting history unless you absolutely have to. Having "trivial" commits is not reason to squash pushed commits. If they can stay, let them stay. And rewriting history is not straightforward in cvs at all, so since these commits would have made their way into the cvs repo, you should probably live with it.

For the git remote repo, if you do wish to proceed - I assume you know to squash the commits on your local repo ( git rebase -i is straightforward). After the squash, push with a -f - a force push.

Upvotes: 27

CharlesB
CharlesB

Reputation: 90496

You can squash the commits with git rebase -i or git merge --squash, see Squash my last X commits together using Git

But since you have already published them to another repository you have to fix it on others. Quite cumbersome, but git push --force is the command you need, though.

It is not recommended, however: if the remote repo has already synced with CVS you'll have to fix it too... Same thing if other devs have already pulled from it.

Upvotes: 14

Related Questions