It goes like this:
I have files A and B that I modified
I'm only suppose to commit and push A, but accidentally committed both and pushed both A and B
I did a "git push old-id:master" so on github it shows "Master is now old-id" where old-id is the last commit before me, so i think it's back to before i committed.
Question:
Note: I do need to keep the changes for both A and B on my local though. The end result should be:
If you want to revert the last commit just do git revert <unwanted commit hash> ; then you can push this new commit, which undid your previous commit. To fix the detached head do git checkout <current branch> .
Git reset doesn't discard all local changes The git reset –hard command will revert uncommitted changes that exist in files that have been added to the index, whether those files are newly created files, or files that were added to the index in the past and have been edited since the last commit.
A revert operation will take the specified commit, inverse the changes from that commit, and create a new "revert commit". The ref pointers are then updated to point at the new revert commit making it the tip of the branch.
$ git reset <old-id> # Undo the commit after old-id $ git add A # stage A for a new commit $ git commit # make the new commit $ git push # push it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With