Re: Checkout deleted semi-untracked file
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Nov 6, 2018, 15:12 UTC
- Message-ID
- <875zxa6xzp.fsf@evledraar.gmail.com>
- In-Reply-To
- <d4624773-739c-f698-514d-458ce2ef5503@tcs.ifi.lmu.de>
On Tue, Nov 06 2018, Steffen Jost wrote:
Show 16 quoted lines
> Hello! > > A brief discussion on the git user mailing list on Google Groups recommended me to file the following as a bug report. > > The problem led to an actual file loss, but I suspect that this might be intended: > > 1) .gitignore is added to the repository (which then causes problems) > 2) A file is added, repeatedly edited and comitted to a remote repository. > 3) Later on, the file is added to .gitignore and "git rm --cached file" is executed (since the file now contains information private to each developer). > 4) Several commits happen. > 5) I checkout an old branch which has not yet seen the change in .gitignore in the master branch. The file is reverted to the state of the branch. > 6) I checkout master, and the file with all later changes is irrevocably lost. > > I usually advise my students to check-in their .gitignore file into the repository. Apparently this is a bad advice, since it now led to a somewhat painful file loss for me. > > So what is the actual advice on this? Google turned up mixed advice there, and the git user mailing list on Google Groups recommended me submitting this as a bug here. However, I think this works as intended. However, I don't know either how to avert this problem, apart from not checking in the .gitignore file (or checking it in under a different name and copying it manually).
This recent thread should be a good starting point: https://public-inbox.org/git/4C6A1C5B.4030304@workspacewhiz.com/
My reply here I think has an overview of some of the caveats: https://public-inbox.org/git/871s8qdzph.fsf@evledraar.gmail.com/
tl;dr: Git assumes that a pattern in .gitignore means you don't care about the contents, since it's meant for *.o and the like. This leads to data loss in some situations (such as yours).
Various suggestions in that thread of ways forward, but none have been implemented>