Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check out a particular version in Git from 'git log'?

Tags:

My git log is showing something as:

enter code here [git_trial]$ git log commit 4c5bc66ae50780cf8dcaf032da98422aea6e2cf7 Author: king <[email protected]> Date:   Thu Jun 30 15:09:55 2011 +0530   This is third commit  commit 8072be67ddd310bc200cab0dccb8bcb2ec4f922c  Author: king <[email protected]>  Date:   Thu Jun 30 14:17:27 2011 +0530  This is the second commit  commit 3ba6ce43d500b12f64368b2c27f35211cf189b68  Author: king <[email protected]>  Date:   Thu Jun 30 14:00:01 2011 +0530   This is the first git commit for file1 

Question 1: Now, how do I check out only my first version?

Question 2: Also, when I do git log on only File1, why does it show only the first commit?

 [git_trial]$ git checkout 3ba6ce43d500b12f64368b2c27f35211cf189b68  Note: moving to "3ba6ce43d500b12f64368b2c27f35211cf189b68" which isn't a local branch  If you want to create a new branch from this checkout, you may do so  (now or later) by using -b with the checkout command again. Example:    git checkout -b <new_branch_name>     [git_trial]$ git log File1    commit 3ba6ce43d500b12f64368b2c27f35211cf189b68    Author: king <[email protected]>   Date:   Thu Jun 30 14:00:01 2011 +0530    This is the first git commit for file1 
like image 499
RajSanpui Avatar asked Jun 30 '11 10:06

RajSanpui


People also ask

How do I see changes in git log?

If you want to see the actual changes introduced by each commit, you can pass the -p option to git log .

How do I find revisions in git?

Just use git rev-parse master (or git rev-parse refs/heads/master if you need to be completely unambiguous). git describe is what I was looking for.


1 Answers

You can checkout a commit using git checkout sha-of-commit which you already have.

But you cannot commit anything (as you're not in a branch, you're in a static commit).

If you need to commit anything on top of that commit, you need to check it out into a branch using git checkout sha-of-commit -b testing-a-commit.

git log <file> only shows commits that affect that file.

like image 50
Dogbert Avatar answered Sep 25 '22 15:09

Dogbert