Let's say I have a single file, foo.txt, that I want to manage with Git, and I don't want to move it into its own directory out of (let's say) /Users/me/Documents, which also has a ton of other files I don't want to include in a repo with foo.txt. Is this possible?
I tried creating a bare repo (so it would not be named .git):
git init --bare .foo.txt
and planned to exclude everything except foo.txt by putting something like this in the info/exclude file:
*
!foo.txt
but the problem I ran into is that I can't even do a git status
as there seems to be no way to pass in a non-standard replacement for the .git directory.
Using a normal .git directory would not work, because it would limit me to ever versioning that one file, or force me to include any other files in the same repo, and I want to be able to version other files in that directory in their own repo.
I realize this is not the use case Git is designed for, but since it's a powerful tool that I'm already familiar with, I'd prefer to use it rather than something else, if there's a way to do that.
Every version of your data is kept in the object database, which lives in the subdirectory . git/objects ; the other residents of . git/ hold lesser data: the index, branch names, tags, configuration options, logs, the current location of the head commit, and so on.
You can do exactly what you want if you first initialize a git repository for the file:
git init --bare .foo.txt
and then run git like this:
git --git-dir=.foo.txt --work-tree=. status
Alias the first part of that second command to git-foo
and you're off to the races.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With