0

In a feature branch of a repository I get mixed messages from git:

λ git status
On branch feature/****
Your branch is up-to-date with 'origin/feature/****'.
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)
  (commit or discard the untracked or modified content in submodules)

        deleted:    path/to/file/abc.tf

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        path/to/file/abc.tf

no changes added to commit (use "git add" and/or "git commit -a")

This file is tracked (and should be) by the remote repository.

How do I resolve these messages so that git status gives me no changes or untracked files?

  • I have tried to git pull -> nothing happens.
  • I have tried a clean install git clone -> Same messages
  • I have tried to remove abc.tf from the directory and then git checkout -f -> back to where I started.
  • I have tried git reset --hard HEAD -> nothing happens.
  • I have not tried commiting the file again, because I would rather not if I can resolve in localy. But maybe that is the only solution?
  • abc.tf is not in my .gitignore

I usually work on linux and these messages dont show there, only on Windows (although I havent tried a clean install on Linux).

Bonus points if you can tell me why this is happening and how to avoid it.

micnil
  • 4,705
  • 2
  • 28
  • 39
  • What does `git checkout path/to/file/abc.tf` result in? If it's `error: pathspec 'path/to/file/abc.tf' did not match any file(s) known to git.` the most likely the repo is corrupt . – Dom Jun 29 '16 at 04:29
  • @Dom I did get that message. And I assume that the remote repository is corrupt aswell. To fix the issue I had to 1: remove abc.tf from the repository. 2: `git add -u` to stage the delete. 3: Put abc.tf back where it was. 4: `git add .`, by now a `git status` said that I had performed a rename of abc.tf to the exact same name. 5: commit and push. If you know why this happens then please post an aswer, otherwise i'll just post my steps to resolve it. thanks. – micnil Jun 29 '16 at 23:49

2 Answers2

1

You didn't post the real file name, but I suspect that what happened is that the files differed only by case (that is, capital/lower-case). I've seen this kind of problem before on Windows, because Git considers files that differ by case as different files, but Windows doesn't.

One thing to try, if possible, is to check out a version of the project before that file existed, and then check out the current version (after the casing was changed).

Community
  • 1
  • 1
Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
  • I know this is a long time ago now, but I remember trying yor suggestion and I remember that it did not help me solve my problem. The problem did not arrise from different casings on the file name (as I could see back then). Still, I found your answer helpful, and maybe it will solve a similar problem for someone else. PS. sorry I took forever to answer – micnil Dec 29 '16 at 10:25
0

I still do not know why this happened, but presumebly the remote branch has been corrupted somehow, here is how I solved it:

  1. remove abc.tf from the repository.
  2. git add -u to stage the delete.
  3. Put abc.tf back where it was.
  4. git add ., by now a git status said that I had performed a rename of abc.tf to the exact same name.
  5. commit and push
micnil
  • 4,705
  • 2
  • 28
  • 39