4

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
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
fas
  • 1,393
  • 10
  • 20

2 Answers2

4

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>
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
0

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.

Marit
  • 2,399
  • 18
  • 27
  • Yes, now I use this, but deleting branch and checkouting requires longer rebuild. – fas May 13 '20 at 09:36