Skip to content

Command line tips and tricks

Nick Desaulniers edited this page Sep 27, 2022 · 29 revisions

Finding the first tag contains a commit in git

Given sha of commit, we want to know the first tag that contains the fix.

tag=$1
git describe --match 'v*' --contains "$tag" | sed 's/[~^].*//'

For finding which commit may have removed a string, try:

$ git log -S <string> <file>

(via Saravana Kannan)

Formatting a commit line

$ git show --format=format:'commit %h ("%s")' 69d0db01e210e07fe915e5da91b54a867cda040f | head -n1
commit 69d0db01e210 ("ubsan: remove CONFIG_UBSAN_OBJECT_SIZE")

Can also be done with git's formatter.

Add this to your .gitconfig file:

[pretty]
	commit = commit %h (\"%s\")

And then generate the formatted message like so:

$ git log -1 --pretty=commit 2de9e73d252d2f1100fcf4dfd7013cc4a93d82d6
commit 2de9e73d252d ("nfsd: use correct format characters")

Similarly can be done for Fixes: ... messages.

Fetching a single patch or series from LKML

Link: https://www.kernel.org/lore.html

Alternatively, you can use a generic message-id redirector in the form: https://lore.kernel.org/r/message@id

Recommend installing b4.

Examples:

# Link to patch (series)
link="https://lore.kernel.org/r/20210204064037.1281726-1-ndesaulniers@google.com/"
or
link="https://lore.kernel.org/lkml/20210204064037.1281726-1-ndesaulniers@google.com/"

# Apply patch (series) in local Git
$ b4 am $link -o - | git am

# Download patch (series)
$ b4 -d am $link

Removing the currently installed kernel and modules

$ sudo rm -r /boot/config-$(uname -r) /boot/initrd.img-$(uname -r) /boot/System.map-$(uname -r) /boot/vmlinuz-$(uname -r) /lib/modules/$(uname -r)

Sending a patch to Linux upstream

Simulate the check of your patch:

$ cd /path/to/linux.git
$ git send-email --dry-run --to-cmd='scripts/checkpatch.pl' 0001-Makefile-correct-prefix-for-Clang-builds.patch

Simulate to get the list of maintainers:

$ git send-email --dry-run --to-cmd='scripts/get_maintainer.pl -i' 0001-Makefile-correct-prefix-for-Clang-builds.patch
  1. Note: Drop --dry-run for a real submission.
  2. Note: Install the package of your distribution shipping git-send-email (Debian: git-email).

Bisecting configs

Make sure to set LLVM=1 when running tools/testing/ktest/config-bisect.pl.

$ LLVM=1 ./tools/testing/ktest/config-bisect.pl

Running KUnit with LLVM

$ ./tools/testing/kunit/kunit.py run --arch=i386 memcpy --make_options LLVM=1