in Education by
As asked in this question, I also want to know how to resolve a conflicting git stash pop without adding all modifications to a commit (just like "git stash pop" without a conflict does). My current approach is very uncool because I do it this way: git stash pop # -> CONFLICT git stash drop # [resolve conflict] # [add conflict files] git reset HEAD # How to reproduce: mkdir foo; cd foo; git init echo "1" > one echo "2" > two git add -A; git commit -m "first" echo "1.1" > one echo "2.1" > two git stash echo "2.2" > two git commit -a -m "second" echo "Only this file would stay in HEAD without the conflict" > third git add third git stash pop git status 2016-06-27: Added a new file called 'third' to the example to show that workarounds like the solution from scy only work for empty HEADs but don't fix the initial problem that the HEAD doesn't have the same content like for a git stash pop without a conflict. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Don't follow other answers... Well, you can follow them, of course. But I don't think that doing a commit and then resetting the branch to remove the commit you just created and similar workarounds suggested in other answers is the clean way to solve this issue. Clean solution The following solution seems to be much cleaner to me and it's also suggested by the Git itself — try to execute git status in the repository with a conflict: Unmerged paths: (use "git restore --staged ..." to unstage) (use "git add ..." to mark resolution) Note: The restore command has been introduced in Git version 2.23.0. Older versions of Git suggested to use the command git reset HEAD ... instead of git restore --staged .... You could also use git reset to unstage any and all files in the staging area (called the index). Restore command's equivalent is git restore --staged . (the dot is necessary and it specifies any file). Currently, any of those commands may be used and the outcome is the same. If you want to learn about the differences between those commands, check the documentation. So let's do what Git suggests (without making and reverting any pointless commits): Manually (or ideally using some merge tool, see below) resolve the conflict(s). Use git restore --staged . to mark conflict(s) as resolved and unstage all files in the staging area. If you want to unstage only specific files, use the command git restore --staged instead. You don't have to execute git add before. Finally, remove the stash with git stash drop, because Git doesn't do that automatically on conflict. Translated to the command-line commands: $ git stash pop # ...resolve conflict(s) $ git restore --staged . $ git stash drop Explanation of the default behavior There are two ways of marking conflicts as resolved: git add and git restore --staged .... While git restore --staged ... marks the conflicts as resolved and removes files from the index, git add also marks the conflicts as resolved, but keeps files in the index. Adding files to the index after a conflict is resolved is on purpose. This way you can differentiate the changes from the previous stash and changes you made after the conflict was resolved. If you don't like it, you can always use git restore --staged . to remove everything from the index. Merge tools I highly recommend using any of 3-way merge tools for resolving conflicts, e.g. KDiff3, Meld, etc., instead of doing it manually. It usually solves all or the majority of conflicts automatically itself. It's huge time-saver!

Related questions

0 votes
    I used git pull and had a merge conflict: unmerged: _widget.html.erb You are in the middle of a conflicted merge. ... can I do this? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    What is the significance of using –index in the git stash pop – – index command? A. To commit the ... To index the files staged D. To pull the staged changes...
asked Dec 23, 2022 in Technology by JackTerrance
0 votes
    How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get ... , i.e. commit 0d1d7fc? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Recently, I have been asked to cherry-pick a commit. So what does cherry-picking a commit in git mean? How do you do it? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I would like to know how to delete a commit. By delete, I mean it is as if I didn't make that commit, ... -hard HEAD. Is this correct? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I usually submit a list of commits for review. If I have the following commits: HEAD Commit3 Commit2 Commit1 ... ... the HEAD commit? Select the correct answer from above options...
asked Feb 3, 2022 in Education by JackTerrance
0 votes
    I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    What is a conflict in Git and how to resolve it?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    How to resolve a conflict in Git?...
asked Nov 2, 2020 in Technology by JackTerrance
0 votes
    I have a project consisting of a huge amount of data. Because of its size, I can't use a remote GIT repo and push/pull ... -ProjectGit | | |-objects |-project1 | |-refs | |-.git...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    My git workspace is dirty, there are some local modifications. When I use the command git pull origin master it ... Ansible git module? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a local git repo and when I do a git push, I need the repo to be pushed to my EC2 instance. ... heads/*:refs/remotes/origin/* Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I cloned a Git repository, which contains about five branches. However, when I do git branch I only see one of ... staging * etc... Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I created a local branch that I want to 'push' upstream. There is a similar question here on Stack ... the upstream repository? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I would prefer to write my commit messages in Vim, but it is opening them in Emacs. How do I configure Git ... for a single project. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
...