Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: can't undo local changes (error: path ... is unmerged)

I have following working tree state

$ git status foo/bar.txt # On branch master # Unmerged paths: #   (use "git reset HEAD <file>..." to unstage) #   (use "git add/rm <file>..." as appropriate to mark resolution) # #       deleted by us:      foo/bar.txt # no changes added to commit (use "git add" and/or "git commit -a") 

File foo/bar.txt is there and I want to get it to the "unchanged state" again (similar to 'svn revert'):

$ git checkout HEAD foo/bar.txt error: path 'foo/bar.txt' is unmerged $ git reset HEAD foo/bar.txt Unstaged changes after reset: M       foo/bar.txt 

Now it is getting confusing:

$ git status foo/bar.txt # On branch master # Changes to be committed: #   (use "git reset HEAD <file>..." to unstage) # #       new file:   foo/bar.txt # # Changed but not updated: #   (use "git add <file>..." to update what will be committed) #   (use "git checkout -- <file>..." to discard changes in working directory) # #       modified:   foo/bar.txt # 

The same file in both sections, new and modified? What should I do?

like image 305
mklhmnn Avatar asked Jun 11 '10 08:06

mklhmnn


People also ask

How do you resolve pulling not possible because you have unmerged files?

To fix the “pulling is not possible” error, you can use git reset –hard. Always write a commit message after adding a file to Git's history. Ensure your files are updated to avoid conflict when pulling changes. You need to commit your changes or stash them before you can merge.

Is it possible to unmerged files git?

Git Pull is Not Possible, Unmerged Files.


1 Answers

You did it the wrong way around. You are meant to reset first, to unstage the file, then checkout, to revert local changes.

Try this:

$ git reset foo/bar.txt $ git checkout foo/bar.txt 
like image 197
Igor Zevaka Avatar answered Sep 23 '22 11:09

Igor Zevaka