Let's say I have been working on a project and at 08:41:11 have pushed my branch to the remote repository's branch (origin/feature/server-java).
git log of my local repo and the remote repo (origin/feature-server-java) look like:
92x301b Change to Server java 08:41:11
91881cc Remove Server GO 08:01:10
5f11b11 Change to yaml config 07:50:55
5f462ff Remove json config 07:10:55
7119093 Remove old config 06:30:33
13829ac New Client URL 06:10:40
Then some of the experienced developers pulled the project and made changes (squashed and deleted some commits) to git commits' history, afterwards he --force pushed that changes to the same remote branch (origin/feature/server-java).
Now remote repo (origin/feature/server-java) looks like (by 10:50:10):
32122ae Add Server 10:50:10
fff5223 Add config yaml 09:50:55
23cc544 Change Client URL 09:10:40
These commit history changes haven't changed source code at all (all tests are still passed as before). But now I wish to git pull that origin/feature/server-java with this changed history. How would I do this? My goal is to completely override the existing my local git commits' history with the remote one.
Seems, that git pull --no-ff origin feature/server-java
doesn't help.
CodePudding user response:
You need to fetch first:
git fetch origin
Then origin/feature/server-java
should be up-to-date with what's in the server. Normally you would want to do git merge
or git rebase
, but if you are sure you don't want any of your local changes, just do:
git reset --hard origin/feature/server-java
Now your branch will be exactly the same as the remote branch.