Nate
Nate

Reputation: 530

How to revert to an earlier commit

Total noob question but I've tried the stuff I've seen online to no avail. I want to make my current head point to an earlier commit. So I look at my git log, find the commit I like, and then type 'git checkout *****'. It then makes the temporary branch (my noob understanding of it) which contains the earlier commit. What do I to make this new branch back to 'master'?

Upvotes: 0

Views: 201

Answers (2)

rufanov
rufanov

Reputation: 3276

You can reset current HEAD to specific commit by using reset command:

git reset --hard <commit-id>

You need to checkout to current branch HEAD first(git checkout <branchname>). Or git will do nothing.

Commit's that been after this commit will be forgotten by git, and will not be shown in history(but they can be easily restored from current repository reflog)

Upvotes: 1

Kenneth M Burling Jr
Kenneth M Burling Jr

Reputation: 19

If you are looking to revert back to a previous commit and pretty much undo the work sense then, check out git reset.

git reset --hard <commit>

will reset the code to that commit.

I would advise that you spend some time reading man git-reset first though, and perhaps make a backup just in case.

Upvotes: 1

Related Questions