gpt4 book ai didi

git-merge - 错误 : The following untracked working tree files would be overwritten by merge:

转载 作者:行者123 更新时间:2023-12-04 05:12:43 25 4
gpt4 key购买 nike

预先感谢您的帮助!

我刚刚完成了 Rails 教程的第 6 章:

http://ruby.railstutorial.org/chapters/modeling-users#sec-6_4

我跑了:

❤ git checkout master

一切顺利,然后我跑了:
❤ git merge modeling-users

并得到以下错误:
Updating fc9f72a..90d1ba6
error: The following untracked working tree files would be overwritten by merge:
app/models/user.rb
Please move or remove them before you can merge.
Aborting

这是我的 app/models/user.rb 文件:
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#

class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password

before_save { |user| user.email = email.downcase }

validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
end

现在我的 Sublime Text 2 user_spec.rb 和 application_helper_spec.rb 文件无法保存并出现以下错误:

Unable to save ~/code/rails_projects/sample_app/spec/models/user_spec.rb



user_spec.rb:
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#

require 'spec_helper'

describe User do

before do
@user = User.new(name: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end

subject { @user }

it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:authenticate) }

it { should be_valid }

describe "when name is not present" do
before { @user.name = " " * 51 }
it { should_not be_valid }
end

describe "when email format is valid" do
it "should be valid" do
addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp a+b@bax.cn]
addresses.each do |valid_address|
@user.email = valid_address
@user.should be_valid
end
end
end

describe "when email format is valid" do
it "should be valid" do
addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp a+b@baz.cn]
addresses.each do |valid_address|
@user.email = valid_address
@user.should be_valid
end
end
end

describe "when email address is already taken" do
before do
user_with_same_email = @user.dup
user_with_same_email.email = @user.email.upcase
user_with_same_email.save
end

it { should_not be_valid }
end

describe "when password is not present" do
before { @user.password = @user.password_confirmation = " " }
it { should_not be_valid }
end

describe "when password doesn't match confirmation" do
before { @user.password_confirmation = "mismatch" }
it { should_not be_valid }
end

describe "when password confirmation is nil" do
before { @user.password_confirmation = nil }
it { should_not be_valid }
end

describe "with a password that's too short" do
before { @user.password = @user.password_confirmation = "a" * 5 }
it { should be_invalid }
end

describe "return value of authenticate method" do
before { @user.save }
let(:found_user) { User.find_by_email(@user.email) }

describe "with valid password" do
it { should == found_user.authenticate(@user.password) }
end

describe "with invalid password" do
let(:user_for_invalid_password) { found_user.authenticate("invalid") }

it { should_not == user_for_invalid_password }
specify { user_for_invalid_password.should be_false }
end
end
end

和我的 application_helper_spec.rb 文件:
require 'spec_helper'

describe ApplicationHelper do

describe "full_title" do
it "should include the page title" do
full_title("foo").should =~ /foo/
end

it "should include the base title" do
full_title("foo").should =~ /^Ruby on Rails Tutorial Sample App/
end

it "should not include a bar for the home page" do
full_title("").should_not =~ /\|/
end
end
end

最佳答案

错误 The following untracked working tree files would be overwritten by merge正在发生是因为有一个 app/models/user.rb当前未添加到任何分支的文件夹中的文件。

您可以通过运行 git status 来验证这一点。命令;它应该显示类似于以下内容的输出:

$ git status
# On branch master
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# app/models/user.rb
no changes added to commit (use "git add" and/or "git commit -a")

当您运行时 git merge modeling-users ,它正在尝试合并 modeling-users分支到 master分支。 modeling-users分支已经有 app/models/user.rb 的副本包含在其中。合并命令使它覆盖文件的未跟踪版本,而该版本已经在 modeling-users 中。分支。因此,错误消息会警告您可能会丢失您想要保留的东西。

git status消息指示,通过运行 git add app/models/user.rb 将文件添加到 master 分支命令。
Unable to save ~/code/rails_projects/sample_app/spec/models/user_spec.rb消息似乎与此无关。从错误消息中不能做太多;也许其他地方有更多信息。

关闭项目并重新打开它可能会有所帮助。您可能还想尝试将文件保存在不同的编辑器中(也许是 vim?)

关于git-merge - 错误 : The following untracked working tree files would be overwritten by merge:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com