Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to change my master to an older commit, how can I do this?

Tags:

git

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?

like image 449
Blankman Avatar asked Dec 05 '10 16:12

Blankman


People also ask

How do I revert a master branch to a previous commit?

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>.

How do I move a master to another 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.


1 Answers

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 
like image 116
Tyler Brock Avatar answered Oct 14 '22 03:10

Tyler Brock