user1449855 user1449855 - 4 months ago 17
Git Question

How can I make an older commit HEAD in Git?

I'm still trying to learn the (basic?) finer points of Git and have managed to get myself into trouble. I realized that I made some mistakes on HEAD, checked out an older commit and started coding from there. When I attempt a push I'm told that my current commit is behind and I need to merge with HEAD. Git recommends "git pull". However, HEAD has the code I want to ignore. How do I solve this problem? Thanks so much for the help.

Flowchart:

-------- HEAD (bad) ---------------------- + (behind conflict, requires
\ / merge with HEAD, which is
\------- Current commit (good) ----/ bad and needs to be ignored)

Answer

If your repository isn't being used by other people, you can safely do git push -f to overwrite the remote branch.

Comments