简体   繁体   中英

How to get the last commit from HEAD in a git repository using libGit2Sharp?

How can I get the last Commit from the current Head?

I guess I need to get the current Branch (repo.Head), then the SHA1 (how?) and then lookup the commit using the SHA1 (how?).

I need to get the last Commit from the current Head. How can I do that?

repo.Head returns the current Branch or the repository.

A Branch exposes a Tip property which points to the latest Commit .

Thus:

  • repo.Head.Tip will return the latest commit of the current Head .

  • repo.Head.Tip.Id the sha of this Commit .

I couldnt find a Testcase which helps me out

You can peek at this test which leverages this kind of code to retreive the sha of the latest commit of the branch pointed at by Head.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM