2013-02-04 56 views
2

在此先感謝您的幫助!錯誤:以下未跟蹤的工作樹文件將被合併覆蓋:

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

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 

這是我的應用程序/模型/ 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+\-.][email protected][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 

現在我的崇高文字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: "[email protected]", 
        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[[email protected] [email protected] [email protected] [email protected]] 
     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[[email protected] [email protected] [email protected] [email protected]] 
     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 

回答

3

錯誤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命令將文件添加到主分支。

Unable to save ~/code/rails_projects/sample_app/spec/models/user_spec.rb消息似乎與此無關。沒有太多可以從錯誤信息中獲得;也許在別的地方有更多的信息。

它可能有助於關閉項目並重新打開它。您可能還想嘗試將文件保存在其他編輯器(vim,也許?)

+0

感謝Prakash! –

相關問題