10
$ git checkout to-branch
$ git merge from-branch
$ git status | grep unmerged
#  file1    unmerged
#  file2    unmerged
#  file3    unmerged
$ vi file1
$ git add .

Eek! I didn't mean to "git add ." I meant to "git add file1"!

Now I can't get behavior like:

$ git show :1:file2

I tried:

$ git reset file2

and

$ git checkout -m file2

but neither of those returns file2 to an "unmerged" state. git status does not show it as unmerged and I don't have access to "git show :1:file2", etc. I want to put the file back into the unmerged state.

How can I go back to the state I was in before "git add ." without losing my changes to file1?

2 Answers 2

15

(Not tested) Did you try

 git checkout -m /path/to/file2
 git checkout -m /path/to/file3

?

When checking out paths from the index, this option lets you recreate the conflicted merge in the specified paths

If this doesn't work, you might have some other answers in the SO question "How do I get my git merge conflicts back after merging incorrectly?"

2
  • Thanks. This does give you the file with merge conflicts but it doesn't update whatever it is that git is using to track merge conflicts so that git status doesn't show the file as unmerged and git show :1:file2, etc. do not work. Will take a look at the other question. Commented Jun 24, 2010 at 13:14
  • +1, Cool -- I didn't know about this obscure feature. Just tried a test with it and it seems to work as advertised. Commented Jun 24, 2010 at 13:20
4

In case anyone's still having this problem (like I did just now), you can (now) do this:

git update-index --unresolve file2 file3

Not the answer you're looking for? Browse other questions tagged or ask your own question.