How to Resolve Git Stash Conflicts Without Commit
This article outlines the steps you should follow to solve Git stash conflicts without reverting or creating commits. For easier context, we will simulate a situation where our git stash pop
command results in a conflict and attempt to solve the conflict without adding the file for commit.
Resolve Git Stash Conflicts Without Commit
On VSCode, we will open our README.md
file, save, add a line at the end, and stash the changes.
$ git stash
Saved working directory and index state WIP on Dev2.1: 8b5cc6c Zesr
Next, we will add another line at the end of our README.md
file, save, and commit the changes.
Now we can run the git stash pop
command.
$ git stash pop
To resolve this without adding the file for commit, follow these steps.
The first step is resolving the merge conflicts. Git has a default mergetool
, but we prefer using Meld
.
If you want to use Meld, make sure it is configured as the default merge and difftool
.
We will run the command below to launch Meld and resolve the conflicts manually.
$ git mergetool
After dealing with the merge conflicts, let’s quickly check the state of our working tree.
$ git status
As seen in the output above, Git has staged the file for commit. We need to run the recommended command to unstage the file.
$ git restore --staged README.md
Let’s check our working tree.
$ git status
Keep in mind that Git does not automatically drop the stash after merging. You will have to drop it by running:
$ git stash drop
In conclusion, we have two ways of marking a Git conflict as resolved. We can use the git add
or the git restore --staged
commands.
The latter will resolve the conflict and remove the file from the index.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn