Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull squashed commit [duplicate]

Tags:

git

git-pull

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
like image 839
fas Avatar asked Oct 19 '25 03:10

fas


1 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>
like image 72
Romain Valeri Avatar answered Oct 21 '25 00:10

Romain Valeri