DEV Community

Ibrahim
Ibrahim

Posted on

How to Abort Conflicts When Using Git Stash Pop

git stash pop is a git command used to apply changes from the recent stash to the current working directory and remove it from the stash list.

This command can cause a conflict. For example:

git stash pop
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
On branch fix
Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
    both modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
The stash entry is kept in case you need it again.
Enter fullscreen mode Exit fullscreen mode

To solve the conflict, you can edit each file that has a conflict manually.

Or you can abort the changes from stash pop with this command:

git reset --merge
Enter fullscreen mode Exit fullscreen mode

The conflicts are now gone after the changes are aborted:

git status
On branch fix
nothing to commit, working tree clean
Enter fullscreen mode Exit fullscreen mode

When git stash pop causes a conflict, the stash applied is not removed from the stash list, so it can be popped again next time.

git reset --merge also discards the files in the staged state (added but uncommitted), so make sure everything in the staged state is clear before you execute this command.

Top comments (0)