Wayne Conrad
Wayne Conrad

Reputation: 107999

File is both modified and untracked

Why I'm asking the question

The following git status output shows a file that is both deleted and untracked:

$ git status
On branch bugfix/1386ReferredBySlow
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified:   Broker/Controllers/InHouseAgentsController.cs
modified:   Broker/Web.config
deleted:    CompanyNameEnterprise.EF/App.Config
modified:   CompanyNameEnterprise.Services/Web.config
Untracked files:
 (use "git add <file>..." to include in what will be committed)
CompanyNameEnterprise.EF/App.config

The file CompanyNameEnterprise.EF/App.config is both "deleted" and "untracked." Those two states seem contradictory.

The Question

Under what circumstances can git show that a file is both untracked and deleted?

More info

How we worked around it.

My co-worker worked around it by re-cloning the project, which fixed the problem (and destroyed the evidence). But I want to know why this can happen so we know what to do next time.

Upvotes: 2

Views: 640

Answers (3)

Rey0bs
Rey0bs

Reputation: 1217

It happens when you remove a file, add the deletion to stage and recreate this file. File will appear in staged and untracked sections.

You can see details with git diff and git diff --staged

Steps to reproduce :

  1. Remove a file with git rm file
  2. Recreate this file with a non-git tool
  3. You can see your file in staged and untracked sections. Use git diff --staged to see changes before addition, and git diff to see changes after addition

Screenshot after remove and restore

A similar thing will appear when you edit a file, add changes to stage and modify the file again. Your file will be appear in staged and unstaged sections. (i.e after a partial addition with git add -p)

Screenshot after double edition

Upvotes: 2

Matthieu Moy
Matthieu Moy

Reputation: 16527

CompanyNameEnterprise.EF/App.config is not modified, it is deleted. In other words, it is present in the last commit but not in the index (aka "staging area").

It is indeed untracked, i.e. present on-disk but not in the index.

To sum up, it is present in the last commit and on disk, but absent from the index. This happens right after your run git rm --cached on the file for example.

Upvotes: 2

user85421
user85421

Reputation: 29680

seems like the problem is related to ignoring the case of the file name: the untracked one has a lowercase 'c' while the deleted one a uppercase 'C'. Maybe the file was renamed?!

I assume the core.ignorecase configuration variable can help: doc (or not if not set correctly).

If true, this option enables various workarounds to enable Git to work better on filesystems that are not case sensitive, like FAT. ...

Use git config --get --show-origin core.ignorecase to check its value and origin.

Upvotes: 5

Related Questions