Troubleshooting misplaced .git directory (nothing to commit)

后端 未结 16 1338
死守一世寂寞
死守一世寂寞 2020-12-05 01:42

I started getting this message. No matter what I edit and try to commit, it says there is nothing to commit. Looks like git does not see my working directory and looking som

相关标签:
16条回答
  • 2020-12-05 02:06

    Found what was wrong. I don't understand how, but .git directory path somehow was changed to other path than I was working in. So then anything I changed was not checked, because git was checking in other place. I noticed it, when I reinitialized it and it showed that it reinitialized entirely different directory. When I cd .. from my current directory and cd to it back again and then reinitialized yet again, then it switched back to correct .git directory and started seeing my changes.

    0 讨论(0)
  • 2020-12-05 02:09

    For anyone seeing this problem, the simplest solution I found was to just "git clone" your repo and delete the old directory. This should set up your pathing correctly by default.

    0 讨论(0)
  • 2020-12-05 02:10

    I just had this problem myself because I was in the wrong folder. I was nested 1 level in, so there were no git files to be found.

    When I execute cd .. to the correct directory, I was able to commit, as expected.

    0 讨论(0)
  • 2020-12-05 02:11

    For people working in public open source projects, if you face this behaviour, it is most likely that the file you are editing is excluded from the git repository using .gitignore. I faced the same behaviour, and after hours I found that the file I was making the change is excluded in .gitignore because it is a settings file, and every one will have their own local version.

    0 讨论(0)
  • 2020-12-05 02:11

    Here is another twist on it. My .gitignore file seemed to have been modified / corrupted so that a file I was ignoring

    e.g.

    /Project/Folder/StyleCop.cache
    

    got changed to this (Note now 2 separate lines)

    /Project/Folder
    StyleCop.cache
    

    so git was ignoring any files I added to the project and below.

    Very weird, no idea how the .gitignore file was changed, but took me a while to spot. Once fixed, the hundreds of css and js files I added went in.

    0 讨论(0)
  • 2020-12-05 02:11

    Don't try commiting / adding files. Just run the following 2 commands (:

        git remote add origin http://xyzremotedir/xyzgitproject.git
        git push origin master
    
    0 讨论(0)
提交回复
热议问题