How to fix: error: '' does not have a commit checked out fatal: adding files failed when inputting “git add .” in command prompt

后端 未结 6 1998
南笙
南笙 2020-12-30 23:51

I\'m trying to add a ruby rails file to my repository in gitlab but it somehow wouldn\'t allow me to add the file saying that my file does not have commit checked out.

相关标签:
6条回答
  • 2020-12-30 23:55

    You don't need to delete the entire file from the directory as the first answer suggests, I just had to delete the .git directory, and then your git add . will work

    This happens for the reason @Mario Zigliotto suggested, there is another repo in a subdirectory under that repo.

    0 讨论(0)
  • 2020-12-30 23:55

    To add to Mario's (correct) answer and resolve this type of issue which can be quite common (e.g.in scaffolding an application using an app generator inside a repository top folder, and it generates its own .git file), you can run the following commands to cleanup and get the files checked in properly to git.

    cd {{appname}}
    rm -rf .git 
    # rm -r -fo .git # if on Windows powershell
    cd ..    
    git add .  
    
    0 讨论(0)
  • 2020-12-30 23:56

    I had the same error Message. I fixed it by deleting the file which causes the error from my Directory.

    I hope this helps =)

    0 讨论(0)
  • 2020-12-31 00:00

    If you have a subdirectory with a .git directory and try to git add . you will see this message.

    This can happen if you have a git repo and then create/clone another repo in a subdirectory under that repo.

    0 讨论(0)
  • 2020-12-31 00:04

    I had the same error message when trying to add multiple files using "git add ." I was able to add all those files one by one instead of all at the same time.

    0 讨论(0)
  • 2020-12-31 00:15

    I had the same Error Message. I fixed it by command below:

    git add folder-name/* instead of git add .

    My Folder directory is like below:

    Main-folder
     -folder-one
     -folder-two
    

    ref: https://github.community/t/error-git-add/2937

    0 讨论(0)
提交回复
热议问题