Edison
Edison

Reputation: 4291

Cannot checkout, file is unmerged

I am trying to remove the file from my working directory but after using the following command

git checkout file_Name.txt

I got the following error message

error: path 'first_Name.txt' is unmerged

What is that and how to resolve it?

Following is my git status

$ git status
On branch master
You are currently reverting commit f200bf5.
  (fix conflicts and run "git revert --continue")
  (use "git revert --abort" to cancel the revert operation)

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

        both modified:      first_file.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        explore_california/

no changes added to commit (use "git add" and/or "git commit -a")

Upvotes: 145

Views: 191980

Answers (9)

cristianoms
cristianoms

Reputation: 3806

If you want to discard modifications you made to the file, you can do:

git reset first_Name.txt
git checkout first_Name.txt

To avoid clashes between the names of your files and of your branches/tags/commits, you can use a double hyphen to separate the command from your local path:

git reset -- first_Name.txt
git checkout -- first_Name.txt

Upvotes: 220

Mahesh Hegde
Mahesh Hegde

Reputation: 1219

Following worked for me

git reset HEAD

I was getting the bellow error

git stash
src/config.php: needs merge
src/config.php: needs merge
src/config.php: unmerge(230a02b5bf1c6eab8adce2cec8d573822d21241d)
src/config.php: unmerged (f5cc88c0fda69bf72107bcc5c2860c3e5eb978fa)

Then i ran

git reset HEAD

it worked

Upvotes: 34

tangyongjun
tangyongjun

Reputation: 1

It works for me.

It will recover file from curreny HEAD

    git restore -S -W file_Name.txt

Upvotes: 0

Liam_1998
Liam_1998

Reputation: 1487

Step 1:

git stash -u

Step 2:

git stash drop stash@{1}

Step 3:

git checkout .

Upvotes: 1

kallayya Hiremath
kallayya Hiremath

Reputation: 4528

i resolved by doing below 2 easy steps :

step 1: git reset Head step 2: git add .

Upvotes: 0

alant
alant

Reputation: 94

In my case, I found that I need the -f option. Such as the following:

git rm -f first_file.txt

to get rid of the "needs merge" error.

Upvotes: 0

steven
steven

Reputation: 560

I don't think execute

 git rm first_file.txt

is a good idea.

  1. when git notice your files is unmerged, you should ensure you had committed it.

  2. And then open the conflict file:

    cat first_file.txt

  3. fix the conflict

4.

git add file

git commit -m "fix conflict"

5. git push

it should works for you.

Upvotes: 4

gcb
gcb

Reputation: 14558

status tell you what to do.

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

you probably applied a stash or something else that cause a conflict.

either add, reset, or rm.

Upvotes: 21

brokenfoot
brokenfoot

Reputation: 11649

To remove tracked files (first_file.txt) from git:

git rm first_file.txt

And to remove untracked files, use:

rm -r explore_california

Upvotes: 37

Related Questions