Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace current branch's head with specific commit in git?

Tags:

git

If I simply do "checkout some_commit" it will switch me to this commit. But what I need is to stay on the current branch (master to be specific) and totally replace all files in it with files from some_commit. How can I do that?

like image 682
lithuak Avatar asked Aug 03 '11 06:08

lithuak


People also ask

How do I switch to a specific commit in git?

Go back to the selected commit on your local environmentUse git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id> .

How do I branch a specific commit?

In order to create a Git branch from a commit, use the “git checkout” command with the “-b” option and specify the branch name as well as the commit to create your branch from. Alternatively, you can use the “git branch” command with the branch name and the commit SHA for the new branch.


1 Answers

git reset --hard <commit>

(I'm sure this is a duplicate, but don't have time to search.)

like image 142
Cascabel Avatar answered Sep 21 '22 20:09

Cascabel