[git] 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")

This question is related to git version-control merge-conflict-resolution

The answer is


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

git rm first_file.txt

And to remove untracked files, use:

rm -r explore_california

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.


Following is worked for me

git reset HEAD

I was getting following 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


i resolved by doing below 2 easy steps :

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


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

git reset first_Name.txt
git checkout first_Name.txt

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.


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.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to version-control

How can I switch to another branch in git? Do I commit the package-lock.json file created by npm 5? Project vs Repository in GitHub Remove a modified file from pull request Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: How to squash all commits on branch git: updates were rejected because the remote contains work that you do not have locally Sourcetree - undo unpushed commits Cannot checkout, file is unmerged Git diff between current branch and master but not including unmerged master commits

Examples related to merge-conflict-resolution

Why does git say "Pull is not possible because you have unmerged files"? Git resolve conflict using --ours/--theirs for all files Cannot checkout, file is unmerged How to interactively (visually) resolve conflicts in SourceTree / git INSERT IF NOT EXISTS ELSE UPDATE? How do I fix a merge conflict due to removal of a file in a branch? Resolving a Git conflict with binary files How to resolve merge conflicts in Git repository?