Git says "not under version control" for the file you just checked out

I have a great impression that my Git repository is somehow malformed.

Here's the sequence I'm following:

  • git clone [remote clone-line]

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

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

    This gives the error message "fatal: not under version control, source = App / And ..."

I originally thought it might be a gitignore thing, but it isn't. I tried Git fsck, it doesn't report anything.

Any suggestions on how to restore it?

+6


source to share


4 answers


Possibly App/android/AndroidManifest.xml

exists, but with a different case (e.g., App/android/AndroidManifest.xml

which means it is App/android/AndroidManifest.xml

not a version (hence the error message):

Doing it git mv

with the right case should be enough.



OP explains in the comments :

It so happened that there were two folders in Git, " App

" and " App

".
When I checked out the repo under Windows, due to Windows case insensitivity, it actually overlaid two folders one on " App

".
This meant that the directory structure was fine, but half of the files (the ones on the " App

" side ) had an invalid Git path!

+8


source


Another feature that left me frustrated, if you are using the command line, it will use your current git mv

file path . So if you have a file inC:\Git\MyRepo\MyFolder\MyFile.txt

If you do:

c:

cd git

cd myrepo

cd myfolder

dir

It will work fine, you will see your file. But if you git mv MyFile.txt MyFile2.txt

get an error because git cannot find Myfile.txt.



The reason is because it looks at your current path, which is called c:\git\myrepo\myfolder\

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

c:

cd Git

cd MyRepo

cd MyFolder

If you type git mv everything works fine.

Include this as an answer for people like me who found this post while debugging this error message.

+2


source


All the answers above are great, I found this when trying to move files around and take advantage of them during the same commit

By fixing my new file path, I could access the new path and then execute the command git mv

(:

task solved

0


source


The situation the OP is facing, as described in the currently selected answer , is caused by the fact that 2 pre-existing folders (or filenames, for that matter) have the same spelling but different case. Firstly, it was a bad choice of name, and hopefully it won't happen very often.

Here, for the sake of completeness, the same "not under version control" error message can also appear when using git bash on Windows , when you have not specified the old filename with the exact correct case.

Example:

  1. Assuming the file path contains mixed case Dir/MyVeryLongFileName.txt

    in your repo and git will store its file path in case sensitive.

  2. Now you git mv dir/MyV

    Tab. Let's say you didn't use TAB autocomplete for a path dir

    , perhaps because it is short enough to type in, and you didn't notice that you typed its first letter incorrectly as d

    and not asD

  3. Since Windows is not case sensitive, TAB autocomplete will still work, so now you have this on the command line

    $ git mv dir/MyVeryLongFileName.txt
    
          

    Now you go ahead to finish your command and, BOOM, you get the error:

    $ git mv dir/MyVeryLongFileName.txt somewhere/else/
    fatal: not under version control, source=dir/MyVeryLongFileName.txt, destination=somewhere/else/MyVeryLongFileName.txt
    
          

    In fact, if you use the same typing style for ls dir/MyV

    Tabyour investigation, bash will tell you that the old file exists (despite the fact that it does not actually write case correctly), which is misleading.

All of the above is not rocket science, but it will be hard enough to raise your blood pressure as you raced over time to prepare your PR. #LearnInTheHardWay

The moral of this story? Use TAB autocomplete even after you have already typed dir. In the example above, typing git mv dir

Tabwill automatically correct the incorrect case and you will get git mv Dir/

. Keep using Tabfor every part of your journey.

-1


source







All Articles