When I try to update project from git I get this error: Couldn't save uncommitted changes

25,081

Solution 1

Go to this repo from git bash.

Then run this command (to check your current unstage changes) :

git status

Then apply below command to stash them :

git stash save "give proper comment to identify it later"

Now to check your unstage changes are in stash or not run this command :

git stash list

Now, you can pull your latest changes from your remote branch. (git pull)

To reapply your stash after pull :

git stash apply stash_id

(here, stash_id is like stash@{n})

Solution 2

I had the same issue. My solution was to set the global git config!

$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]

After that IntelliJ worked fine again.

Solution 3

Your IDE is trying to stash your changes before he does the merge (pull = fetch+merge) and fail to do it.

It is something like this:

Tried to save uncommitted changes in stash but failed with an error.

The easiest thing is to open git bash, check the status and then stash, add or discard your changes.


Few notes:

Intellij has something internal called shelf, its similar to git stash but the files are stored and handled by IntelliJ and not by git, so keet this in mind if you decide to stash (shelf) within the IDE.

Share:
25,081
luffy
Author by

luffy

Updated on July 13, 2020

Comments

  • luffy
    luffy almost 4 years

    I'm new on the job. I work as a junior java developer. We use Intellij IDEA java development editor, git(atlassian) and jira. I have a problem with git. This problem is when I try I get an error what is say "Couldn't save uncommitted changes. Tried to save uncommitted changes in stash before Update, but failed with an error.".

    Here is the screen shots of my git configuration and errors. Here is the my git Intellij config Here is the error what I've got

    • Azat Nugusbayev
      Azat Nugusbayev over 8 years
      1. Commit your changes to your local branch 2. Pull branch from origin branch 3. Resolve conflicts if exists 4. Push your changes to origin
    • Admin
      Admin over 8 years
      see stackoverflow.com/questions/24850247/… (your git config is not OK)
    • luffy
      luffy over 8 years
      I handle it, thank you so much.
  • luffy
    luffy over 8 years
    Ok, I did yo what you said but I don't know git commands.Could you say git commands? And thank you
  • luffy
    luffy over 8 years
    Thank you, I run your first command "git status" but I've got "fatal: Not a git repository (or any of the parent directories): .git" error. Why? My local repo is not exists?
  • Milan Kamboya
    Milan Kamboya over 8 years
    you have to go your repo directory like...if your repo is in this directory : C:/workspace/my_project and under this my_project folder you have your application (under this folder you have .git folder )then got to this directory by cd command and then run these command.
  • luffy
    luffy over 8 years
    Yes, I needn't more help for now. Thank you for your interests.
  • CodeWizard
    CodeWizard over 8 years
    What do you need ill help you as much as i can.
  • luffy
    luffy over 8 years
    No, this error force me to commit my changes. Firstly I committed my changes on project after that I pull.
  • Milan Kamboya
    Milan Kamboya over 8 years
    ok. that is the another way....but this might leads to conflict and you have to solve that thing. tha's why i didn't give you that solution. but you have not conflicts then lucky....
  • luffy
    luffy over 8 years
    Thank you very much, If I can't cope with any problem and find any solution I'll ask. Thank you.