Published: 26.05.2021 | Edited: 26.05.2021 | Tags: 100daystooffload
The fight of gitignores
Roaming around someone else's cloned repository with many different files and fiddling some lines here and there, it is worth using good tools to speed up the process.
Since it is a repository, naturally for me the
git is the go to tool for the version control. Finding files is efficient with the
fd tool, one of the available alternatives for GNU
find. Where it all boils down however is the act of searching through the contents of the files to learn about their intricacies, especially when poking around codebase written in an unfamiliar language or framework.
To quickly find and print files containing a string or a regular expression, the first thing that comes to mind is GNU
grep. However, it too gained a lot of modern alternatives. I use
rg for most of the file content related searches.
Ignoring certain files
The modern alternatives to the standard GNU tools offer many advancements. Apart from the potential speed boots, that might however be negligible in many day-to-day cases, their feature set include ignoring certain files. I have already written excluding ignored files. This post however looks at the topic from a very different angle.
I needed to exclude files from the folder
content/ from polluting the search results. The easiest way would be to put the folder into
rg would pick that up, because it excludes the files ignored by the version control by default. But I did not want to exclude that folder from the version control.
So obviously I have put that folder into not into
.gitignore, but into
.rgignore. The search stopped being polluted and I was happy for a while. A few moments later, during committing, the
.rgignore was showing up as an untracked file. Untracked files can be accidentally committed into the repository unless a great care is taken. This file had nothing to do with the repository, rather it was aiding me in understanding the code, so I did not want to commit it.
Just one more layer
Thus, I have inserted the
.rgignore into freshly created
.gitignore. The situation occurred funny to me, because now
.rgignore was no longer showing up as untracked, but
.gitignore was. So I have basically just added one more layer deferring an issue of not wanting to commit unnecessary file, especially not accidentally.
To close the loop I have inserted
.gitignore into itself alongside
.gitignore to ignore itself. It has probably happen to other people too, but this was my first. But it solved the problems:
- Narrowing the
rgsearch results just to actual code
- Preventing the setting being committed accidentally
- Hiding all the mess created
Have you ever had to gitignore the
.gitignore file itself?
This is a 77th post of #100daystooffload.