Illia Kyzlaitis
Illia Kyzlaitis

Reputation: 25

Git: rollback to certain commit and push it to remote

I am confused with git.

                       I am here
                          |
=>c1=>c2=>c3=>c4=>c5=>c6=>c7 
                   |
              needed commit

How to get the exact code from c5 commit? I don't need c6 and c7 anymore.

Upvotes: 0

Views: 75

Answers (2)

royki
royki

Reputation: 1683

You can do the git revert also. Do the reverts one at a time.

git revert HEAD # Reverts c7

git revert HEAD~2 # Reverts c6

Upvotes: 0

Chris Maes
Chris Maes

Reputation: 37742

If I understand your question well, you want to completely remove commits c6 and c7 FOREVER?

locally:

git reset --hard HEAD~2

then to push to remote (-f to force; THIS IS DANGEROUS!)

git push -f

NOTES:

  • git reset --hard: removes the commits AND all the changes; those commits are lost forever (at least consider them that way, they stay for a short while accessible in git reflog).
  • git push -f: allows you to push to the remote; even if that means you are changing the hash of some commits; this will cause trouble if anyone else is connected to that repository!

Upvotes: 3

Related Questions