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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:23:53+00:00 2026-05-23T11:23:53+00:00

i use git as a version tracker for my c++ project. sometimes i need

  • 0

i use git as a version tracker for my c++ project.

sometimes i need to repeat a calculation and i would like to know which version of the program i used.

what would be a good way to put a # of the commit into the main executable? in other words. i’d like the program to tell me the # of the current commit in an introductory message as i run the program.

one way i can think of is to make the c++ program lunch “git log” from shell and extract the commit # but i’m not sure how to do it during make.

(I use linux)

  • 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-23T11:23:53+00:00Added an answer on May 23, 2026 at 11:23 am

    Probably the easiest way to do this would be to add to your makefile a rule to generate a .c file with the current git commit ID:

    gitversion.c: .git/HEAD .git/index
        echo "const char *gitversion = \"$(shell git rev-parse HEAD)\";" > $@
    

    Now simply add gitversion.c to your build process as normal. Make sure to remove it on make clean, and add it to .gitignore so it’s not added to the git repository accidentally. Add an extern const char *gitversion; to a header somewhere, and you can access it like that.

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

Sidebar

Related Questions

I work on a large Scala project where we use Git for version control.
Short version Need to distribute nightly builds to 70+ people each morning, would like
We're working on quite big project and decided use GIT for version control. I've
I'd like to use git to record all the changes to a file. Is
I am trying to use git and MobileMe as a version control system for
I'm currently starting to use git for my version control system, however I do
I use phpstorm as my IDE, it has git version control integration built in
I use git with my friend to collaborate on a project. He created a
I'm using Git for version control on a Django project. As much as possible,
I have a new project starting up, and I was planning to use git

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.