# git overwriting local ignored files?

6 messages from 2018-11-24 to 2018-11-25. Participants: David Mandelberg, Junio C Hamano, Konstantin Khomoutov.
Thread: https://gitlist.dev/t/49887

## David Mandelberg, 2018-11-24 02:35

Subject: git overwriting local ignored files?
Message-ID: <a852c0e9-f278-8e2a-406c-bb6099b2440c@mandelberg.org>
URL: https://gitlist.dev/e/a852c0e9-f278-8e2a-406c-bb6099b2440c%40mandelberg.org

```
Hi,

It seems that git is overwriting my local files on merge if they're in 
.gitignore. See command transcript below. I searched `git help config` 
and Google, but I couldn't find any way to prevent it. Am I missing 
something? (The reason I care about ignored files is that I'm using git 
with a working directory of $HOME to manage my dotfiles, and most files 
in my $HOME are not tracked by git but are still important.)

dseomn@solaria:~$ mktemp -d
/tmp/tmp.RHyyMxJ5Zp
dseomn@solaria:~$ cd /tmp/tmp.RHyyMxJ5Zp
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ git init --bare repo.git
Initialized empty Git repository in /tmp/tmp.RHyyMxJ5Zp/repo.git/
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ git clone repo.git foo
Cloning into 'foo'...
warning: You appear to have cloned an empty repository.
done.
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ git clone repo.git bar
Cloning into 'bar'...
warning: You appear to have cloned an empty repository.
done.
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ cd foo
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ echo '*' > .gitignore
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git add -f .gitignore
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git commit -m 'gitignore'
[master (root-commit) affd2fb] gitignore
  1 file changed, 1 insertion(+)
  create mode 100644 .gitignore
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 216 bytes | 216.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/tmp.RHyyMxJ5Zp/repo.git
  * [new branch]      master -> master
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ cd ../bar
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git fetch
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
 From /tmp/tmp.RHyyMxJ5Zp/repo
  * [new branch]      master     -> origin/master
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git merge @{u}
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ echo hi > quux
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git add -f quux
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git commit -m 'quux'
[master aee4b54] quux
  1 file changed, 1 insertion(+)
  create mode 100644 quux
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 273 bytes | 273.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/tmp.RHyyMxJ5Zp/repo.git
    affd2fb..aee4b54  master -> master
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ cd ../foo
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ echo bye > quux
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git fetch
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
 From /tmp/tmp.RHyyMxJ5Zp/repo
    affd2fb..aee4b54  master     -> origin/master
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ cat quux
bye
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git merge @{u}
Updating affd2fb..aee4b54
Fast-forward
  quux | 1 +
  1 file changed, 1 insertion(+)
  create mode 100644 quux
dseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ cat quux
hi

-- 
https://david.mandelberg.org/

```

## Junio C Hamano, 2018-11-24 04:22

Subject: Re: git overwriting local ignored files?
Message-ID: <xmqqftvr2jfo.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqftvr2jfo.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <a852c0e9-f278-8e2a-406c-bb6099b2440c@mandelberg.org>

```
David Mandelberg <david@mandelberg.org> writes:

> It seems that git is overwriting my local files on merge if they're in
> .gitignore. See command transcript below. I searched `git help config`
> and Google, but I couldn't find any way to prevent it. Am I missing
> something? (The reason I care about ignored files is that I'm using
> git with a working directory of $HOME to manage my dotfiles, and most
> files in my $HOME are not tracked by git but are still important.)

The .gitignore file is to list "ignored and expendable" class of
files; there is no "ignored but precious class" in Git.

```

## David Mandelberg, 2018-11-24 14:37

Subject: Re: git overwriting local ignored files?
Message-ID: <7ac49733-2e62-7d29-36aa-99df4124b54c@mandelberg.org>
URL: https://gitlist.dev/e/7ac49733-2e62-7d29-36aa-99df4124b54c%40mandelberg.org
In-Reply-To: <xmqqftvr2jfo.fsf@gitster-ct.c.googlers.com>

```
On 11/23/18 11:22 PM, Junio C Hamano wrote:
> David Mandelberg <david@mandelberg.org> writes:
> 
>> It seems that git is overwriting my local files on merge if they're in
>> .gitignore. See command transcript below. I searched `git help config`
>> and Google, but I couldn't find any way to prevent it. Am I missing
>> something? (The reason I care about ignored files is that I'm using
>> git with a working directory of $HOME to manage my dotfiles, and most
>> files in my $HOME are not tracked by git but are still important.)
> 
> The .gitignore file is to list "ignored and expendable" class of
> files; there is no "ignored but precious class" in Git.

Ok. Would a patch be welcome? I have three ideas for how to implement 
it, and I'm not sure which is better.

1. Add a boolean config option called core.preserveIgnore (or similar). 
I'm guessing this is the least amount of work, but it's not very 
flexible. I'm also not sure how it should work with `git clean`.

2. Add some syntax to the .gitignore format so the same file can list 
both "ignored and expendable" and "ignored and precious". I could see 
using this to mark compiled files as ignored+expendable and per-repo 
editor/IDE config files as ignored+precious. Do you have any idea how 
big of a patch this would be? Or any idea for the new syntax? I think 
starting a line with "\x" where x is any character not currently escaped 
by a backslash would cause the least disruption to existing .gitignore 
files.

3. Like (2), but use a separate file instead of .gitignore (and the 
other git-ignore files).

Any thoughts?

-- 
https://david.mandelberg.org/

```

## Konstantin Khomoutov, 2018-11-24 14:57

Subject: Re: git overwriting local ignored files?
Message-ID: <20181124145723.ow2h7x374xwwts6m@tigra>
URL: https://gitlist.dev/e/20181124145723.ow2h7x374xwwts6m%40tigra
In-Reply-To: <7ac49733-2e62-7d29-36aa-99df4124b54c@mandelberg.org>

```
On Sat, Nov 24, 2018 at 09:37:06AM -0500, David Mandelberg wrote:

> > > It seems that git is overwriting my local files on merge if they're in
> > > .gitignore.
[...]
> > The .gitignore file is to list "ignored and expendable" class of
> > files; there is no "ignored but precious class" in Git.
> Ok. Would a patch be welcome? I have three ideas for how to implement it,
> and I'm not sure which is better.
[...]

You might want to first investigate this recent thread [1] which AFAIK
was dedicated to exactly this problem.

1. https://public-inbox.org/git/4C6A1C5B.4030304@workspacewhiz.com/


```

## Konstantin Khomoutov, 2018-11-24 15:41

Subject: Re: git overwriting local ignored files?
Message-ID: <20181124154132.co3lo27wy25i4v47@tigra>
URL: https://gitlist.dev/e/20181124154132.co3lo27wy25i4v47%40tigra
In-Reply-To: <20181124145723.ow2h7x374xwwts6m@tigra>

```
On Sat, Nov 24, 2018 at 05:57:24PM +0300, Konstantin Khomoutov wrote:
> On Sat, Nov 24, 2018 at 09:37:06AM -0500, David Mandelberg wrote:
> 
> > > > It seems that git is overwriting my local files on merge if they're in
> > > > .gitignore.
> [...]
> > > The .gitignore file is to list "ignored and expendable" class of
> > > files; there is no "ignored but precious class" in Git.
> > Ok. Would a patch be welcome? I have three ideas for how to implement it,
> > and I'm not sure which is better.
> [...]
> 
> You might want to first investigate this recent thread [1] which AFAIK
> was dedicated to exactly this problem.

Well, actually the thread is old, but its continuation [2] is recent.
The crux is that it discusses certain approaches to solve the apparent
problem and patches to do that.

1. https://public-inbox.org/git/4C6A1C5B.4030304@workspacewhiz.com/
2. https://public-inbox.org/git/871s8qdzph.fsf@evledraar.gmail.com/


```

## David Mandelberg, 2018-11-25 02:06

Subject: Re: git overwriting local ignored files?
Message-ID: <89204364-f624-62ec-fbaa-84b5b7ae4099@mandelberg.org>
URL: https://gitlist.dev/e/89204364-f624-62ec-fbaa-84b5b7ae4099%40mandelberg.org
In-Reply-To: <20181124154132.co3lo27wy25i4v47@tigra>

```
On 11/24/18 10:41 AM, Konstantin Khomoutov wrote:
> On Sat, Nov 24, 2018 at 05:57:24PM +0300, Konstantin Khomoutov wrote:
>> On Sat, Nov 24, 2018 at 09:37:06AM -0500, David Mandelberg wrote:
>>
>>>>> It seems that git is overwriting my local files on merge if they're in
>>>>> .gitignore.
>> [...]
>>>> The .gitignore file is to list "ignored and expendable" class of
>>>> files; there is no "ignored but precious class" in Git.
>>> Ok. Would a patch be welcome? I have three ideas for how to implement it,
>>> and I'm not sure which is better.
>> [...]
>>
>> You might want to first investigate this recent thread [1] which AFAIK
>> was dedicated to exactly this problem.
> 
> Well, actually the thread is old, but its continuation [2] is recent.
> The crux is that it discusses certain approaches to solve the apparent
> problem and patches to do that.
> 
> 1. https://public-inbox.org/git/4C6A1C5B.4030304@workspacewhiz.com/
> 2. https://public-inbox.org/git/871s8qdzph.fsf@evledraar.gmail.com/

Thanks for the pointers, and sorry to start a new thread. It looks like 
most of the work to do is in finding consensus on the right way forward, 
rather than in writing a patch. While I really would like there be a way 
to prevent git from overwriting ignored files, I don't have any strong 
opinions on what that way should look like. So I think I'll just wait 
and hope somebody else does the work.

-- 
https://david.mandelberg.org/

```
