Skip to content

Command line tips and tricks

Sedat Dilek edited this page Jul 24, 2020 · 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)

For fetching a patch series from the mailing list

Recommend installing b4.

$ b4 am <lore thread url> -o - | git am
# example
$ b4 am \
  https://lore.kernel.org/lkml/CAKwvOdmsap8iB+H5JXiHYwSJFrtQ_krjNH7eQCGe7p-LjK7ftA@mail.gmail.com/T/\#t \
  -o - | git am

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).

Adding references to a commit-id in Git trees from <git.kernel.org>

[ commit (sha1-id) ]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=6526b12de07588253a52577f42ec99fc7ca26a1f
Link: https://git.kernel.org/tip/tip/c/6526b12de07588253a52577f42ec99fc7ca26a1f
[ commit (12 digits) ]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/commit/?id=7b7891c7bdfd
Link: https://git.kernel.org/arm64/c/7b7891c7bdfd

[ patch ]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/patch/?id=6526b12de07588253a52577f42ec99fc7ca26a1f
Link: https://git.kernel.org/tip/tip/p/6526b12de07588253a52577f42ec99fc7ca26a1f
Clone this wiki locally