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 8427843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:53:24+00:00 2026-06-10T04:53:24+00:00

My task at hand is to figure out, what is the commit id of

  • 0

My task at hand is to figure out, what is the commit id of the last commit, where a specific file changed. I’m using ruby / rugged. The only solution I came up with is to walk over all commits, search for the file in the tree associated with the commit for that file and compare that files oid with the oid of the file from the first (latest) commit:

def commit_oid commit, file
    commit.tree.walk( :postorder ) { | root, obj |
        return obj[ :oid ] if "#{root}#{obj[ :name ]}" == file 
    }

    raise "\'#{file}\' not found in repository"     
end

def find_last_commit file
    johnny = Rugged::Walker.new( get_repository )
    johnny.push get_repository.head.target

    oid = commit_oid johnny.first, file
    old_commit = johnny.first.oid

    johnny.each do | commit |
        new_oid = commit_oid commit, file

        return old_commit if new_oid != oid

        old_commit = commit.oid 
    end

    old_commit
end

This works but seems to be quit complicated. There must be an easier ways to get the information, “what changed with a commit”. Is there an easier, more straight forward way to accomplish the same?

  • 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-06-10T04:53:26+00:00Added an answer on June 10, 2026 at 4:53 am

    Running $ git log <file> will give you a reverse chronological log of only commits that altered the given file. $ git whatchanged <file> will do the same, adding a line with details of the change (i.e. mode change, change type). It’s great for visual purposes, but not so much for scripting.

    If you want just the hash of the most recent commit, the following will work well: $ git rev-list --max-count 1 HEAD <file>

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

Sidebar

Related Questions

I have a very simple task at hand. If the last time a record
Task at hand — I have three versions of some code, developed by different
I am new this sharepoint development and i have task in hand to do
the task I want to achieve is import XML file into SQL Server. Once
Let's say we have a very processor-intensive task at hand which could be effectively
I have a fairly easy SQL task at hand and I'd like validation (or
This is the task at hand: I have a db table named 'reports', one
I have a task at hand of creating some kind of logic for a
The task at hand is to login to a website and download a report
I've got the beautiful task at hand to look at some nice legacy asp.net

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.