CONFLICT: Your local changes would be overwritten by stash apply
git stash applyでコンフリクトが発生した場合の対処法
概要
git stash apply または git stash pop を実行した際に、作業ディレクトリの変更とstashの内容がコンフリクトする場合に発生するエラーです。
エラーメッセージ
error: Your local changes to the following files would be overwritten by merge:
path/to/file.js
Please commit your changes or stash them before you merge.
Aborting
CONFLICT (content): Merge conflict in path/to/file.js
原因
- 作業ディレクトリに変更がある - stashを適用しようとするファイルに未コミットの変更がある
- stash作成後にファイルが変更された - stash作成時と現在のファイル内容が異なる
解決策
1. 現在の変更を先にコミット
| |
2. 現在の変更を別のstashに保存
| |
3. コンフリクトを手動で解決
| |
4. –indexオプションなしで適用
| |
5. 特定のファイルのみ復元
| |
stashの確認と管理
| |
よくあるパターン
ブランチ切り替え時のコンフリクト
| |
安全なstash適用
| |
stashをブランチに変換
| |
stash popとstash applyの違い
| |
予防策
| |
関連エラー
関連エラー
Git の他のエラー
この記事は役に立ちましたか?