How to pull squashed commit

Viewed 624

Suppose I have branch, two git clients and git server. Initially all of these have two commits (a and b):

client1:  ...--a--b
client2:  ...--a--b
server:   ...--a--b

I have squashed last two commits on client1 (suppose now it's c) and made git push --force, so now branch looks like:

client1: ...--c
client2: ...--a--b
server:  ...--c

Here's the question: how to pull these changes on client2? git pull --force wants to merge on client2, but I just want to pull changes, so that branch on client2 looks also like:

client2: ...--c
2 Answers

You have to fetch then reset at upstream :

git fetch
git checkout <appropriate branch>
git reset --hard @{upstream}

It will make said local branch point at the same commit its remote counterpart does.

As a sidenote, just in case you might regret commits a and b, you can also make a backup beforehand with

git branch <backup-name> <your-current-branch>

Not exactly what you are asking, but a way to get it done would be to delete the project/branch on client 2, and checkout the remote branch/project again. This also illustrates why you don't want to rewrite history (i.e push force) when commits have already been pushed.

Related