Nam G VU Nam G VU - 11 months ago 36
Git Question

Git get message of a commit with specific .git folder

As discussed here we can get commit message of a given revision via command

$ git log --format=%B -n 1 $revNum

Though this command requires we are inside the git repo folder i.e. somewhere below folder containing
folder. That requires us to pushd and popd to go in and out of the .git folder every time we want to call the command (from external working directory).

I'm looking for params of
git log
command that help to specify .git folder like that. Please share as you know the ones.


My google found me this one though adding
--git-dir=$myCode/.git --work-tree=$myCode
not working for
git log

Answer Source

I think you can use -C option for that. But keep in mind that you need to add the -C option before the git command you want to use (log, status, ...).

For example:

git -C ~/src/docker log

But the following will not work:

git log -C ~/src/docker

You can also use --git-dir, but you cannot use you shell capabilities of globbing in that case and you need to use the full path (no *, ~, etc.):

git --git-dir=/home/nam/src/docker/.git log