Vser
Vser

Reputation: 763

Pass commit hash to a git function in a pretty format

My git repo is huge (and created by people knowing only clearcase) and I want to find all the commits refering to an issue Id on all branches and at the same time knowing which branches contain the commits.

However, the following attempt won't work as the $(git branch …) is expanded before the %h is.

git log --all --oneline --grep="FOO-1337" --pretty=format:"%C(auto)%h $(git branch --contains=%h)"

Is there a shorter solution than looping through the output of git log as in the following:

for commit in $(git log --all --oneline --grep="FOO-1337" --pretty=format:"%h");
do
     branches=$(git branch --contains=$commit | tr '\n' ',')
     git show --oneline --quiet --pretty=format:"%C(auto)%h ${branches}" $commit; 
done

(which I can, of course define as an alias but it seems a bit contrived to me)

Upvotes: 1

Views: 296

Answers (2)

Chris Maes
Chris Maes

Reputation: 37742

If I understand well, you would like your git log command to show all branch names? You could just use the --decorate option which will show all references (branches, tags, ...) for each commit: something like:

git log --all --oneline --decorate ...

If you only want the branches to be shown (and not the tags), you could use:

--decorate-refs=refs/{remotes,heads}/

more information in the git log documentation

Upvotes: 1

DrD
DrD

Reputation: 561

How about including the decorate info in the format:

git log --all --oneline --grep="FOO-1337" --pretty=format:"%C(auto)%h %D"

won't that do the trick?

Upvotes: 1

Related Questions