Conversation

I usually have lots of git branches with various iterations of whatever I'm working on. And I lose track what each branch contains. git range-diff is great, but a bit tedious.

Here's a helper alias to "range compare" two branches. It finds their common ancestor, and range diffs them.

Usage: git range-compare rev1 [rev2]

~/.gitconfig:
[alias]
range-compare = "!f() { rev1=${1:?no branch to compare to}; rev2=${2:-HEAD}; git range-diff $(git merge-base $rev1 $rev2) $rev1 $rev2; }; f"

2
1
1

This is what I have to create pretty commit citations of the form d206a76d7d27 ("Linux 6.8-rc6").

Usage: git cite <commit-ish>

~/.gitconfig:
[alias]
cite = "!f() { git log -1 '--pretty=format:%H (\"%s\")%n' $1 | sed -e 's/\\([0-f]\\{12\\}\\)[0-f]*/\\1/'; }; f"

4
3
1

@jani comparing branches. I haven’t used your solution but the sl command helps me track the differences in my branches. Maybe these are different things.

0
0
0

@jani In the Mesa docs we recommend a 'git fixes' alias that could be repurposed for this:

> fixes = show -s --pretty='format:Fixes: %h (\"%s\")'

This seems to give a reasonably short SHA1 without the sed.

1
0
0

@mattst88

FWIW, the kernel has this in process/submitting-patches.rst

"'"
The following ``git config`` settings can be used […]:

[core]
abbrev = 12
[pretty]
fixes = Fixes: %h (\"%s\")

An example call::

$ git log -1 --pretty=fixes 54a4f0239f2e
Fixes: 54a4f0239f2e ("KVM: MMU: make kvm_mmu_zap_page() return the number of pages it actually freed")
"'"

/me wonders he is missing something that @jani's approach does better

1
0
0
@kernellogger @mattst88 @jani I do something like Jani, why would I want to type that git log command when I can have an autocompleteable git alias..
1
0
0

@conor @jani @mattst88

Yeah, I totally understand that; but what I don't understand is that sed stuff (but again, I guess I might be missing something here)?

2
0
0

@kernellogger @conor @jani @mattst88 I read that as grabbing the first 12 characters of the hash.

1
0
0

@jani Thanks for posting this! I've been missing it ever since I stopped having the drm maintainer tools installed on my system. Now I can just stuff that in my .gitconfig and off we go.

0
0
0

@jani Personally I have the following which seems equivalent:

[core]
abbrev = 12
[pretty]
cite = %h (\"%s\")
[alias]
cite = log -1 --pretty=cite

0
0
0

@jani @mattst88

FWIW, I was curious and tried, this works:

cite = "!f() { git log -1 --abbrev=12 --pretty='format:%h (\"%s\")%n' $1; }; f"

0
0
0

@jani @1ace @mattst88

👏

Guess we now just need someone to add this to the kernel's documentation

0
0
1
@1ace @kernellogger @jani @mattst88

That's nice, it seems to enable the pager for me by default with that though, so have stuck a !git --no-pager in front
0
0
1