ITChap
ITChap

Reputation: 4742

git checkout commit with specific trailer

I have an orphan branch (let's call it output) which contains the documents generated by templates stored on my main branch. I would like to checkout the commit on output that correspond to a specific commit on main.

I settled on using git commit --trailer 'Source: xxxxx' when committing on output where xxxxx is the corresponding commit on main.

Is it possible to checkout a commit on output knowing only the value of its trailer?

Upvotes: 1

Views: 379

Answers (3)

VonC
VonC

Reputation: 1328152

To be sure to match a commit with a trailer (and not just a commit message whose topic happens to include Source: xxxxx), you can use the "%(trailers[:options])" format.
And use git switch (not checkout), or git show to just see the content (without modifying the current working tree)

git switch \
$(git log --pretty=format:"%H% (trailers:key=Source,valueonly)"|grep Junio|head -1|cut -d " " -f1)

Upvotes: 2

phd
phd

Reputation: 94827

git show ':/Source: xxxxx'

See the docs on :/ in git help revisions.

Upvotes: 1

ElpieKay
ElpieKay

Reputation: 30938

To find the sha1 value of a commit that has the trailer Source: xxxxx,

git log --pretty=%H --grep='Source: xxxxx'

To check out the commit in one step,

git checkout $(git log --pretty=%H --grep='Source: xxxxx')

Upvotes: 2

Related Questions