ScientiaEtVeritas
ScientiaEtVeritas

Reputation: 5278

Get Commit Hash of Previous Commit that changed a specific File

To get the previous commit key / hash of another commit key there is COMMITKEY^1.

But in context of a file (e.g. Example.java), is there a way to get the previous commit to another that changed Example.java somehow?

Upvotes: 0

Views: 94

Answers (2)

1615903
1615903

Reputation: 34879

git log -1 --pretty=%h <base commit> -- Example.java will print the the latest commit that has touched the Example.java file starting from <base commit> (thanks to ElpieKay). The base commit can be i.e. HEAD~1 if you want to start looking from the previously made commit.

Upvotes: 1

LuFFy
LuFFy

Reputation: 9307

Use Below Command :

git log --name-status

which will show output as :

commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Author: xyzauthor <[email protected]>
Date:   Mon Apr 24 20:16:07 2017 +0530

    changes done in folder name

M       filename.java

Now Just use git checkout with commitID as below :

git checkout xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Upvotes: 0

Related Questions