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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:30:44+00:00 2026-06-06T16:30:44+00:00

I have a central Git bare repository. When a push is made to that

  • 0

I have a central Git bare repository. When a push is made to that repo I want to run a post-receive hook. What that hook will do is create a message on a Basecamp project (using their API). I want info on the update that was just performed. Right now I think git log -2 --stat is good enough but would like a little more info (branch that was updated, file created, files removed). Can anyone help with the command(s) I need to do to get all the info? Performing multiple commands is fine with with me, there probably isn’t a single command that will get me all the information.

  • 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-06T16:30:45+00:00Added an answer on June 6, 2026 at 4:30 pm

    You could find the latest commit by examining and sorting the files under .git/refs/heads: every time a new commit is made, the corresponding refs/heads file is changed, i.e. when committing to master, refs/heads/master is updated.

    So, let’s develop a solution.

    First task: find all branches (i.e. all files under refs/heads and print out when they were last changed. You’re talking about hooks, so we give the path relative to the .git/hooks directory:

    find ../refs/heads -type f -printf '%T@ %p\n'
    

    This produces a list of all branches along with their change date. See the man page of find for an explanation of the parameters.

    Second Task: sort the obtained list

    find ../refs/heads -type f -printf '%T@ %p\n' |\
    sort
    

    Third Task: we need the newest element in that list. Since sort sorts from old to new, our desired item is at the bottom of the list. Get this element with tail (only one item, therefore pass the -1 flag):

    find ../refs/heads -type f -printf '%T@ %p\n' |\
    sort    |\
    tail -1
    

    Fourth Task: drop the date in the obtained line. From our printf statement we know that date and path are separated with a space. Feed this as delimiter into cut (-d " ") and tell it we need the second field (i.e. the file path, -f 2). For convenience, we’ll store this file path in a variable called $LATESTHEAD:

    LATESTHEAD=$(\
        find ../refs/heads -type f -printf '%T@ %p\n' |\
        sort    |\
        tail -1 |\
        cut -d ' ' -f 2 )
    

    Fifth Task: Now we know the filename, but we need the content. This is the latest revistion that could be passed to git log. cat does the job. Store the latest revision in $LATESTREV

    LATESTHEAD=$(\
        find ../refs/heads -type f -printf '%T@ %p\n' |\
        sort    |\
        tail -1 |\
        cut -d ' ' -f 2 )
    LATESTREV=$(cat $LATESTHEAD)
    

    Now, you could use $LATESTREV to do any dirty things you want.

    Perhaps not the most elegant solution (probably someone will come up and tell you a much easier one-liner) but works for me.

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

Sidebar

Related Questions

I have a central git repository that everyone pushes to for testing and integration,
I have a bare repository that's used as the central store for my project.
I have a server that contains a central git repository and one of my
I have a local git repository a central repo at github. I'm working on
I currently have Git setup with a central bare repository which is accessed by
I want to have a bare git repository stored on a (windows) network share.
I have successfully made, committed, and pushed changes to a central git repository. I
I have several non-bare Git repositories. There is one central Git repository (or at
I have made a central bare shared repo at foo.org. user A has done
I have a central git repository which myself and several collaborators regularly push and

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.