LoginSignup
0
0

More than 3 years have passed since last update.

AWS 修正ファイルを本番環境でgit pull したらエラーが発生した / error: The following untracked working tree files would be overwritten by merge:

Posted at

どんなエラー

既にAWSでデプロイ済みのファイルを修正して、更新する際に下記のエラーが発生しました。

terminal
[ec2-user@XXXX XXX]$ git pull
Updating 98941d5..33a4f3d
error: The following untracked working tree files would be overwritten by merge:
    vendor/bundle/ruby/2.5.0/bin/byebug
    vendor/bundle/ruby/2.5.0/bin/coderay
    vendor/bundle/ruby/2.5.0/bin/dotenv
    vendor/bundle/ruby/2.5.0/bin/geocode
    vendor/bundle/ruby/2.5.0/bin/nokogiri
    vendor/bundle/ruby/2.5.0/bin/pry
    vendor/bundle/ruby/2.5.0/bin/puma
    vendor/bundle/ruby/2.5.0/bin/pumactl
    vendor/bundle/ruby/2.5.0/bin/rackup
        〜略〜
    vendor/bundle/ruby/2.5.0/cache/nokogiri-1.10.10.gem
    vendor/bundle/ruby/2.5.0/cache/orm_adapter-0.5.0.gem
    vendor/bundle/ruby/2.5.0/cache/pry-0.13.1.gem
    vendor/bundle/ruby/2.5.0/cache
Aborting

こちらの解決策を記載していきます。

その前に、更新の手順

その前に、修正したファイルをAWSに更新するまでの手順を記載しておきます。
①下記のコマンドを実行します。

terminal
$ git add . && git commit -m "ローカルで変更した点をadd commitする"
$ git push origin 修正したブランチ
$ ls ~/.ssh
$ ssh -i ~/.ssh/practice-aws.pem ec2-user@パブリックアドレス
# これでes2へログインします

Last login: Sun Nov  1 XX:XX:XX XXX from softbankXXXXX.bbtec.net

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

# これがでればログイン完了

②次に、下記のコマンドを実行します。
全てrs2上です。

terminal
[ec2-user@XXXXX]$ ls
APP TEST_APP HAPPY_APP 
[ec2-user@XXXXX]$ cd APP/
[ec2-user@XXXXX APP]$ sudo service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[ec2-user@XXXXX APP]$ kill $(cat tmp/pids/puma.pid)
[ec2-user@XXXXX APP]$ git pull

③また、それぞれの修正箇所によって下記のコマンドを実行します。

terminal
# gem関連に変更
[ec2-user@XXXXX]$ bundle install --path vendor/bundle --without test development
# DBに変更
[ec2-user@XXXXX]$ bundle exec rails db:migrate RAILS_ENV=production
# css, js, 画像に変更
[ec2-user@XXXXX]$ bundle exec rails assets:precompile RAILS_ENV=production

④最後に、下記を実行したら終了です(おそらく)。

terminal
[ec2-user@XXXXX]$ rails s -e production
=> Booting Puma
=> Rails 5.2.4.4 application starting in production 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.6 (ruby 2.5.7-p206), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: production
* Daemonizing...

エラーの解消方法

上記の手順を進めていく中で、②の部分で下記のエラーが発生しました。

terminal
[ec2-user@XXXX XXX]$ git pull
Updating 98941d5..33a4f3d
error: The following untracked working tree files would be overwritten by merge:
    vendor/bundle/ruby/2.5.0/bin/byebug
    vendor/bundle/ruby/2.5.0/bin/coderay
    vendor/bundle/ruby/2.5.0/bin/dotenv
    vendor/bundle/ruby/2.5.0/bin/geocode
    vendor/bundle/ruby/2.5.0/bin/nokogiri
    vendor/bundle/ruby/2.5.0/bin/pry
    vendor/bundle/ruby/2.5.0/bin/puma
    vendor/bundle/ruby/2.5.0/bin/pumactl
    vendor/bundle/ruby/2.5.0/bin/rackup
        〜略〜
    vendor/bundle/ruby/2.5.0/cache/nokogiri-1.10.10.gem
    vendor/bundle/ruby/2.5.0/cache/orm_adapter-0.5.0.gem
    vendor/bundle/ruby/2.5.0/cache/pry-0.13.1.gem
    vendor/bundle/ruby/2.5.0/cache
Aborting

本番環境でpullしたらコンフリクト?解決法3パターン!【Please commit your changes or stash them before you merge】の方の記事を参照しましたら、解決できました。
ありがとうございます🙏

terminal
[ec2-user@XXXX XXX]$ git fetch origin master
From https://github.com/jnn-natsumi/XXX
 * branch            master     -> FETCH_HEAD

[ec2-user@XXXX XXX]$git reset --hard origin/master
HEAD is now at 33a4f3d Merge pull request #24 from XXXX/Fmypage

[ec2-user@XXXX XXX]$ git pull
Already up-to-date.

pull できてるっぽい?
次に、下記のコマンドを実行しました。

terminal
[ec2-user@XXXX XXX]$ rails s -e production
Could not find concurrent-ruby-1.1.7 in any of the sources
Run `bundle install` to install missing gems.

# bundle installしてくださいと言われているので、実行

[ec2-user@XXXX XXX]$ bundle install
Your Gemfile lists the gem rspec-rails (>= 0) more than once.
You should probably keep only one of them.
〜略〜
Bundle complete! XX Gemfile dependencies, XXX gems now installed.
Gems in the groups test and development were not installed.
Bundled gems are installed into `./vendor/bundle`
Post-install message from i18n:

[ec2-user@XXXX XXX]$ rails s -e production
=> Booting Puma
=> Rails 5.2.4.4 application starting in production 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.6 (ruby 2.5.7-p206), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: production
* Daemonizing...

なんとか無事に修正を更新できました。
何が起きていたのか、ちゃんと調べて、理解しておきます。
解決への記事をあげてくれた方、ありがとうございます🙏

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0