go-git icon indicating copy to clipboard operation
go-git copied to clipboard

How to get the latest commit only by path?

Open cbl315 opened this issue 4 years ago • 5 comments

Description

Hi guys, I want to get the latest commit of specific path and it should be equal to below command:

git log -n 1 --pretty=format:%H -- path/to/folderOrFile

I try to get the log by g.Log as showed in this example:

https://github.com/go-git/go-git/blob/da810275bf682d29a530ed819aff175f47bd7634/_examples/log/main.go#L18-L47

But now it seems LogOptions don't support -n argument.

Any idea about it?

Thx

cbl315 avatar Jun 22 '21 02:06 cbl315

Could we add -n arguments in ListOptions?

cbl315 avatar Jun 22 '21 13:06 cbl315

You can get just one commit with:

commit, err := cIter.Next()
cIter.Close()

jfontan avatar Jun 22 '21 20:06 jfontan

You can get just one commit with:

commit, err := cIter.Next()
cIter.Close()

FYI what I want actually is that the cIter just store the latest commit like -n 1 do.

cbl315 avatar Jun 23 '21 01:06 cbl315

The ability to find the latest commit of a specific file is impacted by https://github.com/go-git/go-git/issues/811 on projects with sizeable commit history.

bryfry avatar Nov 26 '23 03:11 bryfry

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

github-actions[bot] avatar Feb 27 '24 07:02 github-actions[bot]