Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git says "not under version control" for just-checked-out file

Tags:

git

I have the distinct impression my Git repo is somehow mangled.

Here's the sequence I'm doing:

  1. git clone [remote's clone string]

    This creates, among many others, a file "App/android/AndroidManifest.xml"

  2. git mv App/android/AndroidManifest.xml App/android/AndroidManifestTemplate.xml

This gives the error message:

fatal: not under version control, source=App/And..."

Initially I thought this might be a gitignore thing, but that's not it either. I tried git fsck, it doesn't report anything.

Any suggestions on how to repair it?

like image 951
Doktor Schrott Avatar asked Oct 15 '14 14:10

Doktor Schrott


3 Answers

Maybe App/android/AndroidManifest.xml does exist, but with a diferent case (like App/android/androidmanifest.xml, which would mean that App/android/AndroidManifest.xml isn't versioned (hence the error message):

Doing the git mv with the right case should then be enough.

The OP explains in the comments:

What happened was that there were two folders in Git, "App" and "app".
When I checked out the repo under Windows, because of the case-insensitivity of Windows, it actually overlayed the two folders into one into "App".
Which meant, the directory structure was fine, but half of the files (the ones coming from the "app" side) had an invalid Git path!

like image 66
VonC Avatar answered Nov 10 '22 09:11

VonC


Most easiest way to solve this issue is to first we need to add the file first and then we need to rename the file

$ git add file-name

$ git mv current-file-name new-file-name

and then your problem will be solve. Screenshot for above issue

like image 20
reecha soni Avatar answered Nov 10 '22 10:11

reecha soni


Another quirk that left me frustrated is if you're using the command line, it will use your current path to git mv the file. So if you have a file in C:\Git\MyRepo\MyFolder\MyFile.txt

If you do:

c:

cd git

cd myrepo

cd myfolder

dir

It will work fine, you'll see your file. But if you type git mv MyFile.txt MyFile2.txt you will get an error because git can't find Myfile.txt.

The reason is that it's looking at your current path, which is c:\git\myrepo\myfolder\

But git is case sensitive. So you have to go back and type

c:

cd Git

cd MyRepo

cd MyFolder

If you then type git mv it will work fine.

Putting this in as an answer for people like me that found this post while debugging this error message.

like image 5
NibblyPig Avatar answered Nov 10 '22 10:11

NibblyPig