threads / discuss / 62171

Using Git as a Database

Subject: Using Git as a Database

## tl;dr

6 messages between Sep 23, 2024 and Sep 25, 2024.

replies: 5people: 5as markdown or json

Mateusz Wielgos· Sep 23, 2024, 03:28 UTC · lore
Hello,
I would like to use Git as a database of sorts. Let’s say I want to track weight of something in a file. When the value changes I can commit the new one. I can also figure out all previous values. That’s awesome.
What I am having trouble with is… What if a measurement is taken but there’s no change? I want to commit a file that hasn’t changed.
The only workaround I figured out is to toggle the executable bit.
Is there anything else?

Thanks, Mateusz

email@mateuszwielgos.com· Sep 23, 2024, 12:32 UTC · re: 韩仰 · lore

Re: [External] Using Git as a Database

Thank you for your reply, Han. The problem that I have with ‘—allow-empty’ is that the resulting commit is not associated with any particular file. I tried ‘git commit —allow-empty myfile.txt’ but the file argument is effectively ignored. ‘git log myfile.txt’ does not show the empty commit.
Show 7 quoted lines
> On Sep 22, 2024, at 10:48 PM, 韩仰 <hanyang.tony@bytedance.com> wrote:
> 
> You can use the --allow-empty option in git-commit to allow
> such commits.
> 
> Thanks,
> Han
Andreas Schwab· Sep 23, 2024, 18:42 UTC · re: email@mateuszwielgos.com · lore

Re: [External] Using Git as a Database

On Sep 23 2024, email@mateuszwielgos.com wrote:
> Thank you for your reply, Han. The problem that I have with ‘—allow-empty’ is that the resulting commit is not associated with any particular file. I tried ‘git commit —allow-empty myfile.txt’ but the file argument is effectively ignored. ‘git log myfile.txt’ does not show the empty commit.

Since the git model is snapshot based, there is no way around that, apart from putting the reference in the commit message which you can search with git log --grep=myfile.txt.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
rsbecker@nexbridge.com· Sep 23, 2024, 19:09 UTC · re: Andreas Schwab · lore

RE: [External] Using Git as a Database

On September 23, 2024 2:43 PM, Andreas Schwab wrote:
Show 10 quoted lines
>On Sep 23 2024, email@mateuszwielgos.com wrote:
>
>> Thank you for your reply, Han. The problem that I have with ‘—allow-empty’ is
>that the resulting commit is not associated with any particular file. I tried ‘git commit
>—allow-empty myfile.txt’ but the file argument is effectively ignored. ‘git log
>myfile.txt’ does not show the empty commit.
>
>Since the git model is snapshot based, there is no way around that, apart from
>putting the reference in the commit message which you can search with git log --
>grep=myfile.txt.

One way around this is to inject a date/timestamp in the file. Be careful about conflicts If you every try to merge. This forces a signature change in the internal blob on commit.

I am not recommending this, just suggesting a way to force the issue.
Sergey Organov· Sep 25, 2024, 16:47 UTC · re: Mateusz Wielgos · lore

Re: Using Git as a Database

Mateusz Wielgos <email@mateuszwielgos.com> writes:
Show 11 quoted lines
> Hello,
>
> I would like to use Git as a database of sorts. Let’s say I want to
> track weight of something in a file. When the value changes I can
> commit the new one. I can also figure out all previous values. That’s
> awesome.
>
> What I am having trouble with is… What if a measurement is taken but
> there’s no change? I want to commit a file that hasn’t changed.
>
> The only workaround I figured out is to toggle the executable bit.

As you are tracking weight or something like that over time, it's likely useless without date, so just put time-stamp into the file as well:

85kg 2024-09-25 19:45:14
-- Sergey

← back to recent threads