Jump to content

Random helpful hints

From NicheWork
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This is a list where I record (currently) random helpful hints that I've discovered.

Find which git branch the work you want is stored on

I keep several branches going all at once, so sometimes I remember the tool I need (e.g. server-info in pyproject.toml) but not where I left it.

$ git branch --format='%(refname:short)' | xargs -I {} sh -c 'git show {}:pyproject.toml 2>/dev/null | grep -q "server-info" && echo "Found in branch: {}"'
Found in branch: hosts-query-tool

Remove .git subdirectory from my repo

At some point in the history of my dotfiles repo, I had accidentally added a .git subdirectory. When I tried to push it to gitlab, I got the following:

remote: error: object 4e158169…: hasDotgit: contains '.git
remote: fatal: fsck error in packed object
error: remote unpack failed: index-pack abnormal exit

After some trial and error, I came up with the following solution:

$ git filter-repo --analyze
Processed 60787 blob sizes
Processed 6996 commits
warning: exhaustive rename detection was skipped due to too many files.
warning: you may want to set your diff.renameLimit variable to at least 42160 and retry the command.
Processed 7599 commits
Writing reports to .git/filter-repo/analysis...done.
$ awk '/\.git$/ {print $4}' .git/filter-repo/analysis/directories-all-sizes.txt | xargs -n 1 --verbose git filter-repo --invert-paths --path
git filter-repo --invert-paths --path dotfiles/emacs.d/lisp/twittering-mode/.git
Parsed 7600 commits
New history written in 0.93 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
HEAD is now at d5699c710 working config
Enumerating objects: 112030, done.
Counting objects: 100% (112030/112030), done.
Delta compression using up to 8 threads
Compressing objects: 100% (58765/58765), done.
Writing objects: 100% (112030/112030), done.
Total 112030 (delta 42497), reused 111993 (delta 42463), pack-reused 0 (from 0)
Completely finished after 10.16 seconds.
git filter-repo --invert-paths --path dotfiles/emacs.d/lisp/emacs-pdt/.git
Parsed 7600 commits
New history written in 1.20 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
HEAD is now at e82cb045b working config
Enumerating objects: 111991, done.
Enumerating objects: 111991, done.
Counting objects: 100% (111991/111991), done.
Delta compression using up to 8 threads
Compressing objects: 100% (58723/58723), done.
Writing objects: 100% (111991/111991), done.
Total 111991 (delta 42487), reused 111980 (delta 42477), pack-reused 0 (from 0)
Completely finished after 9.97 seconds.
$

This, of course, requires git-filter-repo which you can install with apt or uv:

$ uv tool install git-filter-repo
Resolved 1 package in 60ms
Installed 1 package in 9ms
 + git-filter-repo==2.47.0
Installed 1 executable: git-filter-repo
$