Eduardo Bezerra
Eduardo Bezerra

Reputation: 1963

git: How to get the latest commit on a specific file, regardless of branch?

I have this big repository containing different modules, which should have been broken down in different repositories, one for each module. Sometimes I created a branch, say featbranch, in the repo to work on a specific module, but featbranch had no meaning at all for other modules. You can imagine the mess this could cause...

Anyway, my question is: how do I get the latest commit that changed a specific file, and possibly which branch such commit belongs to? By "latest", I just mean the one with highest timestamp, as I understand that commits from different branches would likely not have any precedence relation.

Upvotes: 3

Views: 603

Answers (1)

CB Bailey
CB Bailey

Reputation: 791869

git log -n 1 --date-order --all -- <file>

(Note, this might not be the commit with the latest timestamp if someone has made "an older" commit directly on top of a newer commit. This can only happen is someone is lying about the time when they make a commit, though.)

Upvotes: 8

Related Questions