1

I pushed the code twice on my repo and pulled it on the server, It had some issues so I had to go back and hard reset to a previous commit. Can I only get changes from last commit ?

Command I used to go back to commit 'C'

git reset --hard C

Visual representation:

commits on repo:

A-B-C-D-E-F

git on server side:

A-B-C'

Locally I only want to push some changes that are in commit 'F'. Now i want to pull changes only from the commit 'F' and skip 'D,E'. On server it tells me I am three commits behind and when I pull it gets files from all the commits. I only want files updated in 'F' commit or any other latest commit.

(Sorry for bad english)

2 Answers2

2

To pull changes from F git cherry-pick origin/F then you need to push out your new changes. git push -f origin. This will remove D and E from your branch on the server side.

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
1

git reset --hard HEAD~1

git push -f

(Example push: git push -f origin bugfix/bug123)

This will undo the last commit and push the updated history to the remote. You need to pass the -f because you're replacing upstream history in the remote.

And if you want revert or undo a no of commits let's say 3 then the command will change like

git reset --hard HEAD~3

git push -f

For more info

Magaesh
  • 488
  • 6
  • 19