I want to rollback to a previous commit, and then publish that code, then go back to the latest commit.
i.e. so my master is pointing to an older commit version just so I can pulish that version, then I want to go back to the latest commit I was one initially.
How can I do this?
When you want to revert to a past commit using git reset – – hard, add <SOME-COMMIT>. Then Git will: Make your present branch (typically master) back to point at <SOME-COMMIT>. Then it will make the files in the working tree and the index (“staging area”) the same as the versions committed in <SOME-COMMIT>.
Use git branch <branch> to create a new branch at the tip of the current master . Use git reset HEAD~<n> --hard to rewind back <n> commits and discard changes. Use git checkout <branch> to switch to the new branch. Only works if the changes have only been committed locally and not pushed to the remote.
If you want to do this and revert the master to the previous commit:
git checkout master~1 # Checkout previous commit on master git checkout -b new_master # Create branch for new master git branch -D master # Delete old master git branch -mv new_master master # Make new_master master
Alternatively:
git reset --hard master~1 # Reset current branch to one commit ago on master
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