LoginSignup
0
0

More than 1 year has passed since last update.

git stashでコンフリクトが起きたときの対処

Posted at

【Git】git stashでコンフリクトが起きたときの対処

git stashは現在のブランチで変更をコミットせずに退避・一時保存できるコマンド

たまに遭遇するケース

結構前に退避したものをgit stash popgit stash applyで元に戻そうとした時、色々なコミットを取り込んでしまっていると、場合によっては以下のような感じでコンフリクトが起きることがある

# 1 退避
git stash

# 2 別の人のコミットなどを取り込んだ後に元に戻そうとする
git stash apply stash@{0}

# 3 コンフリクトが起きる
error: Your local changes to the following files would be overwritten by merge:
        ~/ファイル名
Please commit your changes or stash them before you merge.
Aborting

そんな時に使うコマンドがgit stash branch <newbranch>コマンド

git stash branch <newbranch>の使い方

これは新しいブランチを作成し、作業スタックに退避した時点のコミットを再現して、スタックにある作業を再適用してくれる

つまりstashコマンドを実行した時点のブランチの状態に戻せるようなイメージ

# new-branchブランチを作成し、そっちのブランチに適用
git stash branch new_branch stash@{0}
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