96

I cloned a repository and want to switch to a commit to test my plugin against the core.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
xZise
  • 2,321
  • 5
  • 22
  • 31

2 Answers2

157

Instead of passing the name of a branch, you can pass any commit ID to checkout:

git checkout <commit-id>

See the man page.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
20

Step 1: fetch list of commits:

git log

You'll get list like in this example:

[Comp:Folder User$ git log
commit 54b11d42e12dc6e9f070a8b5095a4492216d5320
Author: author <author@gmail.com>
Date:   Fri Jul 8 23:42:22 2016 +0300

This is last commit message

commit fd6cb176297acca4dbc69d15d6b7f78a2463482f
Author: author <author@gmail.com>
Date:   Fri Jun 24 20:20:24 2016 +0300

This is previous commit message

commit ab0de062136da650ffc27cfb57febac8efb84b8d
Author: author <author@gmail.com>
Date:   Thu Jun 23 00:41:55 2016 +0300

This is previous previous commit message
...

Step 2: copy needed commit hash and paste it for checkout:

git checkout fd6cb176297acca4dbc69d15d6b7f78a2463482f

Thats all.

Igor
  • 12,165
  • 4
  • 57
  • 73