views:

70

answers:

2

I'm developing a Linux kernel module outside of the Linux source tree (in the standard way) and am trying to automatically include the git commit hash of the driver into the version string printed out during the module load. The Makefile computes the git hash using the command

DRV_TAG   := $(shell git log -1 --pretty=format:"%h")

but this picks up the git hash of the Linux tree and not my driver. Can you tell git to look at a particular directory when executing commands, or alternatively, is there is a better way of approaching this problem?

This is using git 1.5.4.5 and Linux 2.6.28

+1  A: 

Yes, you can use the --git-dir option which you should set to the appropriate .git directory. Also, while you can use git log, for what you're doing rev-parse (a plumbing command) might be more suitable.

git --git-dir=/driver/root/.git rev-parse HEAD
Charles Bailey
+1  A: 

git takes an option --git-dir which lets you specify what repository to look in. There's an analogous --work-tree option if you need to look at the work tree too.

git --git-dir=/path/to/repo log -1 --pretty=format:"%h"

Look at the git man page for descriptions of these and other options.

Jefromi