Ruby on Rails项目创建异常:仅生成文件无文件夹且报错
解决Rails new命令无法创建项目文件夹的Git相关异常
执行rails new blog创建Ruby on Rails项目时,仅生成README.md、Rakefile等根文件,未创建完整项目文件夹,同时出现以下错误:
E:\Gamess\Ruby>rails new blog create create README.md create Rakefile create .ruby-version create config.ru create .gitignore create .gitattributes create Gemfile run git init from "." C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/generators/rails/app/app_generator.rb:258:in ``': No such file or directory - git config init.defaultbranch (Errno::ENOENT) from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/generators/rails/app/app_generator.rb:258:in `user_default_branch' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/generators/rails/app/app_generator.rb:76:in `version_control' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/generators/app_base.rb:134:in `public_send' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/generators/app_base.rb:134:in `build' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/generators/rails/app/app_generator.rb:328:in `create_root_files' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:134:in `block in invoke_all' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:134:in `each' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:134:in `map' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:134:in `invoke_all' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/group.rb:232:in `dispatch' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/commands/application/application_command.rb:26:in `perform' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/command/base.rb:87:in `perform' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/command.rb:48:in `invoke' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/lib/rails/cli.rb:18:in `<top (required)>' from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require' from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-7.0.6/exe/rails:10:in `<top (required)>' from C:/Ruby30-x64/bin/rails:25:in `load' from C:/Ruby30-x64/bin/rails:25:in `<main>'
解决方法
临时方案:跳过Git初始化
创建项目时添加--skip-git参数,绕过Git相关步骤:
rails new blog --skip-git
永久方案:修复Git环境
- 安装Git:如果未安装Git,下载安装包并完成安装,注意勾选「Add Git to your PATH」选项(默认通常已勾选)
- 验证Git可用性:打开命令行执行
git --version,能正常输出Git版本号即为配置成功 - 重新创建项目:执行
rails new blog即可正常生成完整项目文件夹
内容的提问来源于stack exchange,提问作者Byruat
相关产品推荐
相关产品推荐

