🦊

git

Cheers to tobhe and sbeattie \o/

git log -1 --format=%ct $COMMIT

create patch

git format-patch --no-stat --stdout -1 $COMMIT > foo.patch

recent log summary

git shortlog --since="one week"

check which tags contain commit

git tag --contains $COMMIT

check GitHub pull request

git fetch origin pull/ID/head:BRANCH_NAME

Kernel style “Fixes” oneliner

Append to ~/.gitconfig:

[pretty]
       # format used in fixes lines, also useful for general references
       fixes = Fixes: %h (\"%s\")

Use with:

$ git show -q --format=fixes $COMMIT
Fixes: 3f30a274913 ("libiberty: Update D symbol demangling for latest ABI spec.")

cleanly merge remote branch (without GitHub UI)

Rebase remote branch with the upstream branch you intend to merge with:

cd my-fork/
git checkout my-branch
git fetch upstream
git rebase -i upstream/main
git push --force

Prep for merge:

cd non-remote-git/
# update
git remote add eslerm git+ssh://[email protected]/~eslerm/my-fork
git remote update eslerm
git checkout main

Because there are no interleaved commits after rebase, git will fast forward merge. To preserve the branch, use --no-ff:

git merge --no-ff eslerm/my-branch
git push

diff file commits

git difftool --tool=vimdiff --no-prompt $commit1 $commit2 -- $file

nb: this works on refs, branches do not matter

git-blame-someone-else

https://github.com/jayphelps/git-blame-someone-else

git blame ignore

git blame --ignore-rev $COMMIT
# or
echo $COMMIT >> .git-blame-ignore-revs

Useful for black.

remove secret or onerous files

Nightwatch Cybersecurity claimed a CVE in git, because they did not understand how git refs work. Junio clarified that CVE-2022-24975 is not a vulnerability or bug to Nightwatch Cybersecurity before the CVE was assigned.

visualize branch topology

git log --graph --decorate --oneline

or:

tig

tig status

tig status

edit files and stage or unstage them (u).

backlog notes

Add notes from So You Think You Know Git - FOSDEM 2024.

amend batch of commits

This is destructive to history.

Rollback commits:

git rebase -i HEAD~7

To sign, after each ^pick line:

exec git commit --amend --no-edit -S