# Using Git as a Database

6 messages from 2024-09-23 to 2024-09-25. Participants: Mateusz Wielgos, 韩仰, email@mateuszwielgos.com, Andreas Schwab, rsbecker@nexbridge.com, Sergey Organov.
Thread: https://gitlist.dev/t/62171

## Mateusz Wielgos, 2024-09-23 03:28

Subject: Using Git as a Database
Message-ID: <4B2B1EC7-6B08-4B57-A50F-702C031C2792@mateuszwielgos.com>
URL: https://gitlist.dev/e/4B2B1EC7-6B08-4B57-A50F-702C031C2792%40mateuszwielgos.com

```
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


```

## 韩仰, 2024-09-23 03:48

Subject: Re: [External] Using Git as a Database
Message-ID: <CAG1j3zEg47RLYrVfJQi7WubgcdtbK2RWFBtj5rd8NtkPyXU5Rg@mail.gmail.com>
URL: https://gitlist.dev/e/CAG1j3zEg47RLYrVfJQi7WubgcdtbK2RWFBtj5rd8NtkPyXU5Rg%40mail.gmail.com
In-Reply-To: <4B2B1EC7-6B08-4B57-A50F-702C031C2792@mateuszwielgos.com>

```
You can use the --allow-empty option in git-commit to allow
such commits.

Thanks,
Han

```

## email@mateuszwielgos.com, 2024-09-23 12:32

Subject: Re: [External] Using Git as a Database
Message-ID: <0D0BB87D-9BF0-48BA-8F2D-83F8D326ECEC@mateuszwielgos.com>
URL: https://gitlist.dev/e/0D0BB87D-9BF0-48BA-8F2D-83F8D326ECEC%40mateuszwielgos.com
In-Reply-To: <CAG1j3zEg47RLYrVfJQi7WubgcdtbK2RWFBtj5rd8NtkPyXU5Rg@mail.gmail.com>

```
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.

> 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, 2024-09-23 18:42

Subject: Re: [External] Using Git as a Database
Message-ID: <87r09aus7v.fsf@igel.home>
URL: https://gitlist.dev/e/87r09aus7v.fsf%40igel.home
In-Reply-To: <0D0BB87D-9BF0-48BA-8F2D-83F8D326ECEC@mateuszwielgos.com>

```
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, 2024-09-23 19:09

Subject: RE: [External] Using Git as a Database
Message-ID: <00d001db0dec$1c8fa320$55aee960$@nexbridge.com>
URL: https://gitlist.dev/e/00d001db0dec%241c8fa320%2455aee960%24%40nexbridge.com
In-Reply-To: <87r09aus7v.fsf@igel.home>

```
On September 23, 2024 2:43 PM, Andreas Schwab wrote:
>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, 2024-09-25 16:47

Subject: Re: Using Git as a Database
Message-ID: <87jzezhe89.fsf@osv.gnss.ru>
URL: https://gitlist.dev/e/87jzezhe89.fsf%40osv.gnss.ru
In-Reply-To: <4B2B1EC7-6B08-4B57-A50F-702C031C2792@mateuszwielgos.com>

```
Mateusz Wielgos <email@mateuszwielgos.com> writes:

> 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

```
