2

I committed my code and when I do a git pull I found some conflicts. How do I solve the conflicts and only get the file version from pulling without my committed changes?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Firdous
  • 4,624
  • 13
  • 41
  • 80
  • possible duplicate of [How do I resolve a conflict after git pull?](http://stackoverflow.com/questions/1435754/how-do-i-resolve-a-conflict-after-git-pull) – CharlesB Sep 07 '11 at 16:44

2 Answers2

8

you can do

git reset --hard HEAD^

git pull

Unstage all of your changes and do a fast-forward merge. There is no need to solve the conflict anymore.

TheOneTeam
  • 25,806
  • 45
  • 116
  • 158
  • but this link says that hard reset is before you commit: http://book.git-scm.com/4_undoing_in_git_-_reset,_checkout_and_revert.html – Firdous Sep 07 '11 at 16:47
  • and untill i dont resolve my conflicts i cant do "git revert HEAD" – Firdous Sep 07 '11 at 16:49
  • @Firdous: then you should do reset --hard HEAD^ instead of HEAD. which would reset your stage before commit. Rmb, all of your committed changes will be lost! – TheOneTeam Sep 07 '11 at 16:55
  • fatal: 'revert' is not possible because you have unmerged files. Please, fix them up in the work tree, and then use 'git add/rm ' as appropriate to mark resolution and make a commit, or use 'git commit -a'. – Firdous Sep 07 '11 at 17:08
  • @Firdous: I wonder if you have created a commit? Did you type git commit for your changes before? please use RESET not REVERT. – TheOneTeam Sep 07 '11 at 17:19
2

You can hard reset your branch to the commit before your changes, and then cherry pick each of the subsequent commits. This will bring your branch to a state that includes everything except for your changes.

Kevek
  • 2,534
  • 5
  • 18
  • 29
  • but this link says that hard reset is before you commit: http://book.git-scm.com/4_undoing_in_git_-_reset,_checkout_and_revert.html – Firdous Sep 07 '11 at 16:44
  • 1
    hard reset will always just force your current branch to be set to whatever branch/tag you specify. You can do it whenever. The danger is that it will throw away uncommitted changes, or create a dangling branch that isn't referred to anymore. To keep yourself save in those situations, you could always create a new branch where you are before you hard reset, since creating branches is so cheap in Git. Then, if anything goes wrong, you could just hard reset to the temporary branch you created and then you're back to exactly where you were (and you can try again!) – Kevek Sep 07 '11 at 16:47
  • ok, i did it, and yes it worked (conflicts resolved), and when i do "git status" there is no modified file (perfect). now how do i pull? b/c if i do pull it shows conflict errors. i cant understand that when i have no modified file then how are the conflicts coming? i m new to git as u can see :) – Firdous Sep 07 '11 at 17:02
  • 1
    I personally would load gitk (gitk --all&) and then right click each commit I want to grab (assuming there are only a few, as in, half a dozen to two dozen) and click "Cherry-pick This Commit", that way you will end up with a branch that has everything on the head except for your changes. You can then push this/do whatever you want with it. It will have excluded your changes that are causing the conflict – Kevek Sep 07 '11 at 17:09