Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6941111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:50:36+00:00 2026-05-27T12:50:36+00:00

I want to implement git log -1 fullpath/myfile with libgit2. I am fairly new

  • 0

I want to implement git log -1 fullpath/myfile with libgit2. I am fairly new to libgit2. Am I on the right track? This is what I have so far:

git_repository_head(&refToHead, repo);

headOID = git_reference_oid(refToHead);
git_commit_lookup(&headCommit, repo, headOID);

headTreeOID = git_commit_tree_oid(headCommit);
git_tree_lookup(&tree, repo, headTreeOID);

git_tree_entry_byname(tree, "repopath/myfile");

Unfortunately git_tree_entry_byname seems not to work for files in subdirectories of the repo. Any idea?

Thank you,
Lars

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:50:37+00:00Added an answer on May 27, 2026 at 12:50 pm

    Unfortunately git_tree_entry_byname seems not to work for files in
    subdirectories of the repo.

    git_tree_entry_byname only works against the entries (trees, blobs and, when supported, submodules) which are immediately under the passed tree.

    One simple solution to your question would be to rely on git_tree_get_subtree (see tests) to retrieve the deepest subtree contained in a tree, given its relative path. This would work no matter how deep the entry is in the tree structure.

    Thus, you’d have to call git_tree_git_subtree to retrieve the parent tree of the entry you’re after, then invoke get_tree_entry_byname passing it the parent tree.

    I want to implement git log -1 fullpath/myfile with libgit2

    If you’re willing to retrieve which commit lastly updated a file, you might want to take a look at this answer which gives some general purpose hints on the file history topic and caveats.

    I can’t find any clue to get the commit in your linked answer.

    You’ll have to leverage the revision walking API.

    • Description of the feature can be found here.
    • A test demonstrating different walking strategies may also provide you with some help

    Basically, you’d have to find out from the HEAD the oid of the tree entry matching your filename. Once this is done you’d have to recursively walk the parents of the HEAD commit and, for each commit tree, try and identify one of the two following changes.

    • Detect if the file has been renamed (the tree entry has disappeared from its parent tree, a new file with the same oid popped up under the parent tree)
    • Detect if the content of the file has changed (the tree entry still exists with its name but its oid has changed).

    Exit from the loop ass soon as you detect one, or when you have no more commit to process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have WSDL and XSD files and want implement a webservice based on this
i want implement geolocation notification like the app reminders. this is what i have
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I want to implement an automatic update system for a windows application. Right now
I want to implement a simple debug log, which consists of a table into
i have question for example i want to implement binary tree with array i
I want to implement CI for my project, but I've never done this before.
I want to implement carriage return within xslt. The problem is I have a
I am new to Graph concept in android. In my app i want implement
I want implement in my software solution an VBA editor but in c# 3.0.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.