git-stamp
Update files with Git commit information
TLDR
Stamp the last commit message referencing it with the issue number from your bug tracker
Stamp the last commit message linking it to its review page
Stamp the last commit message replacing previous issues with a new one
SYNOPSIS
git-stamp [-h | --help] [-V | --version] [-f | --force] [-s STRING | --string=STRING] object.o [object.o ...]
PARAMETERS
-h, --help
Print usage message and exit
-V, --version
Print version information and exit
-f, --force
Force overwrite even if a git stamp already exists in the .comment section
-s STRING, --string=STRING
Use the specified STRING as the stamp instead of running git describe
DESCRIPTION
git-stamp is a utility that embeds a version string, typically from git describe, into the .comment section of ELF object files (.o files).
It automatically runs git describe --dirty --always --tags 2>/dev/null || echo 'unknown' to generate a concise version identifier like v2.3.1-13-gabc1234-dirty, then uses GNU objcopy to insert this string into the object file's comment section.
This is particularly useful in build systems (e.g., Makefiles, CMake) for embedding build-time version information directly into executables or libraries without external files. The stamped info survives linking and can be extracted later using tools like readelf -p .comment, strings, or objdump.
By default, it skips stamping if a git stamp already exists to avoid overwriting custom comments, but --force overrides this. Custom strings can be provided via --string for non-Git projects or specific needs.
Requires objcopy from binutils and works only on ELF files (Linux, *BSD). Ideal for open-source projects ensuring binaries carry traceable version metadata for debugging, reproducible builds, or compliance.
CAVEATS
Requires GNU binutils objcopy; supports only ELF object files. Non-ELF files (e.g., Mach-O) are ignored. Runs git in the current directory—ensure a valid repo. Existing non-git comments may be overwritten with --force. Not suitable for stripped or final binaries.
EXAMPLE USAGE
git-stamp foo.o
Stamps current git describe into foo.o.
git-stamp -s 'v1.2-custom' bar.o baz.o
Stamps custom string into multiple files.
Verify: readelf -p .comment foo.o | grep git
EXTRACTION
Post-linking, extract from binary: readelf -p .comment /path/to/executable or strings executable | grep -i git. Note section may be concatenated if multiple stamps.
HISTORY
Developed by Eric S. Raymond (ESR) as a lightweight tool for embedding Git metadata in builds. First released around 2015, hosted on GitLab at gitlab.com/esr/git-stamp. Evolved from needs in portable build environments; version 1.1.0 as of recent commits. Commonly used in projects like SDL and other C/C++ software for version stamping.
SEE ALSO
git-describe(1), objcopy(1), readelf(1), strings(1)


