Search code examples
gitgit-stash

git stash pop : discard local changes in a single file


On my-branch

 git stash
 git checkout master
 git pull --rebase
 git checkout my-branch
 git rebase master
 git stash pop

Everything is ok but only 1 file has conflicts and I do not want the changes that I stashed. There are bunch of other files which are not conflicting and those changes are needed.

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
  both modified:   /server/Server.java

How do I get rid of these changes and have a clean stash pop ?


Solution

  • git checkout HEAD -- /server/Server.java
    

    to discard local changes and check out the state of the file as recorded in HEAD i.e. the current commit.