101

I have working directory (#1) which has vendor directory(#2) in it. There is one dependency which I wanted to pull manually without composer (php version of npm/gem). I was working in #1, haven't saved/commited changes, when I decided I want to update library in #2. I navigated to vendor/myname, and did git pull repository.

Unfortunately it started to pull and merge to #1, instead of creating new directory in vendor folder.

Now I have:

  • #1 folder with my changes
  • #1 folder with files I don't want from wrong repository
  • #1 merge conflicts such as composer.json, Readme.md... (general files)

I want to "undo" this last git pull without loosing any changes I did to folder #1. How can I do this?

2
  • Git prevents pull or merge if there are uncommitted changes, are you sure this is what hapepned?
    – CharlesB
    Commented Sep 9, 2013 at 7:08
  • 1
    @CharlesB It aborted merge, projects are not jet merged. I know nothing about git preventing before pull...
    – ewooycom
    Commented Sep 9, 2013 at 7:45

3 Answers 3

197

git merge --abort might be what you're looking for.

2
  • 7
    In older git versions: git reset --merge
    – razz0
    Commented Jul 8, 2014 at 6:57
  • It works, but unhelpfully tells you nothing. Do a git status to confirm.- Commented Jun 26, 2015 at 19:11
22

Modern Git:

git merge --abort

Older:

git reset --merge

Old-school (warning: will discard all your local changes):

git reset --hard

But actually, it is worth noticing that git merge --abort is only equivalent to git reset --merge given that MERGE_HEAD is present. This can be read in the git help for merge command.

git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present.

After a failed merge, when there is no MERGE_HEAD, the failed merge can be undone with git reset --merge but not necessarily with git merge --abort, so they are not only old and new syntax for the same thing. Personally I find git reset --merge much more useful in everyday work.

5

With Git 2.10 (Q3 2016), you will know what to do, because git status will propose the git merge --abort option.

See commit b0a61ab (21 Jul 2016) by Matthieu Moy (moy).
(Merged by Junio C Hamano -- gitster -- in commit 5a2f4d3, 03 Aug 2016)

status: suggest 'git merge --abort' when appropriate

We already suggest 'git rebase --abort' during a conflicted rebase.
Similarly, suggest 'git merge --abort' during conflict resolution on 'git merge'.

Not the answer you're looking for? Browse other questions tagged or ask your own question.