Cannot checkout, file is unmerged
GitVersion ControlMerge Conflict-ResolutionGit Problem Overview
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")
Git Solutions
Solution 1 - Git
If you want to discard modifications you made to the file, you can do:
git reset first_Name.txt
git checkout first_Name.txt
Solution 2 - Git
To remove tracked files (first_file.txt) from git:
git rm first_file.txt
And to remove untracked files, use:
rm -r explore_california
Solution 3 - Git
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
Solution 4 - Git
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.
Solution 5 - Git
I don't think execute
git rm first_file.txt
is a good idea.
-
when git notice your files is unmerged, you should ensure you had committed it.
-
And then open the conflict file:
cat first_file.txt
-
fix the conflict
git add file
git commit -m "fix conflict"
5.
git push
it should works for you.
Solution 6 - Git
Step 1:
git stash -u
Step 2:
git stash drop stash@{1}
Step 3:
git checkout .
Solution 7 - Git
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.
Solution 8 - Git
i resolved by doing below 2 easy steps :
step 1: git reset Head step 2: git add .