3

I am using php-git client to pull branches in my php script. and whenever i do checkout from master to testing i get following error.

error: Pull is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

my files are on bitbucket server. and i add/modify files on bitbucket and commit there.

I dont understand , I dont mofify anything on my local machine, still i get this error.

Following is my 'git status' output.

Your branch is up-to-date with 'origin/testing'.

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:

    modified:   g_1.0.yaml
    new file:   potter_3.4.yaml
    new file:   potter_3.4.yml

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

    both modified:   abc_1.0.json
Nilesh
  • 442
  • 1
  • 4
  • 22
  • Run `git status` in that folder/directory. – Brahma Dev Sep 25 '17 at 11:31
  • 1
    `Exiting because of an unresolved conflict` ... the error message cannot be any clearer than this. Type `git status` to see which of your files are still in conflict. – Tim Biegeleisen Sep 25 '17 at 11:32
  • added my git status output, my question is if i am not modifying anything locally, everything get modified on server, why i get this error? – Nilesh Sep 25 '17 at 11:35
  • You have clearly changed something in the file G_1.0.yaml just run git diff "g_1.0.yaml" to see your changes. – Thrawn Sep 25 '17 at 11:37
  • Yes i changed this, but the difference is I have changed this file directly on bitbucket.org under my personal repo, and committed changes there, I havent modified anything from locally, then why i am getting this error locally while pulling repo – Nilesh Sep 25 '17 at 11:47
  • 1
    Whether or not you modified things locally, you have run `git merge` (probably by running `git pull`) and gotten a merge conflict. I always advise those new to Git to avoid `git pull` entirely: it just does two Git commands, and you're better off if you run those two Git commands yourself, so that you can tell when one of them has gone wrong (which is what happened at some point in the past, leaving you with this mess now). – torek Sep 25 '17 at 16:47
  • Does this answer your question? [Why does git say "Pull is not possible because you have unmerged files"?](https://stackoverflow.com/questions/26376832/why-does-git-say-pull-is-not-possible-because-you-have-unmerged-files) – Flimm Jan 03 '22 at 12:38

4 Answers4

13

You are in the middle of a merge, try to read the messages you copied, it's pretty clear what you should do: You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge)

So first clear up the merge conflicts

use the merge tool of your choice (eg: tortoise merge, meld )
or do it by hand, in the conflicted file you should see arrows like <<<<<<< HEAD, select the appropriate one(s)

and then commit

git commit -m "foobar"

Now you should be able to push/pull from your remote, but you may need to pull first, to get the new changes merged locally.

Alternatively, if you don't need your code, and just want to toss out everything and get master, you can allays

git reset --hard origin/master

to reset your local repo to the state of origin/master, but you will loose all local changes

MrKekson
  • 720
  • 6
  • 18
  • 1
    Thanks for the answer, but my question is, I haven't done these changes from locally, it has been modified and committed over bitbucket.org under my personal remote repo, and now when i pull it , i get mentioned error – Nilesh Sep 25 '17 at 12:26
  • I don't know what have you done, ( you can check with "git reflog" ). – MrKekson Sep 25 '17 at 13:06
  • But most likely, someone pushed to your repo, or you merged something to your main, and when you pulled back to your local, there was a conflict. But this situation is pretty normal, so get some good merge-ing tool. – MrKekson Sep 25 '17 at 13:08
  • Also, take a look at abc_1.0.json, it was modifyed locally in your repo, and on the remote too. So search for the >>>>>> <<<<<<< arrows in it. – MrKekson Sep 25 '17 at 13:20
2

If you don't want to merge changes and still want to update your locale, run:

git reset --hard HEAD 

This will reset your local with the head and then pull your remote using the git pull.

If you've already committed your merger locally (but haven't gone remote yet), and would like to return it again:

git reset --hard HEAD~1
Syscall
  • 19,327
  • 10
  • 37
  • 52
Md.Milton
  • 41
  • 3
0

There is a file in the Unmerged paths: section : abc_1.0.json.

This is the sign of a conflict. It probably appeared when you ran a previous git pull from this same branch.


You now have to choose :

  1. if you know that you have something which you modified in abc_1.0.json, and that you need to keep this modification in this file, resolve the conflict :

    • open abc_1.0.json in your editor
    • look for the conflict markers (lines looking like : <<<<< HEAD, =====, >>>>> testing)
    • choose what version should be kept
  2. if you know that the current merge is not important, you can run git merge --abort, and try to pull again.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

If there are unmerged paths that are being staged, you'd need to unstaged them. To find out unmerged paths:

git status

To unstage all:

git restore --staged .

Now you'd be able to pull the changes.

Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68