Jump to content

Random helpful hints: Difference between revisions

From NicheWork
branch search
 
filter-repo
 
Line 8: Line 8:
$ git branch --format='%(refname:short)' | xargs -I {} sh -c 'git show {}:pyproject.toml 2>/dev/null | grep -q "server-info" && echo "Found in branch: {}"'
$ 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
Found in branch: hosts-query-tool
</syntaxhighlight>
== Remove <tt>.git</tt> subdirectory from my repo ==
At some point in the history of my dotfiles repo, I had accidentally added a <tt>.git</tt> subdirectory.  When I tried to push it to gitlab, I got the following:
<syntaxhighlight lang="shell-session">
remote: error: object 4e158169…: hasDotgit: contains '.git
remote: fatal: fsck error in packed object
error: remote unpack failed: index-pack abnormal exit
</syntaxhighlight>
After some trial and error, I came up with the following solution:
<syntaxhighlight lang="shell-session">
$ 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.
$
</syntaxhighlight>
This, of course, requires [https://github.com/newren/git-filter-repo git-filter-repo] which you can install with [https://packages.debian.org/search?keywords=git-filter-repo apt] or [https://docs.astral.sh/uv/getting-started/installation/ uv]:
<syntaxhighlight lang="shell-session">
$ 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
$
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 00:12, 21 January 2026

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
$