1

I pulled some changes from a remote repository:

git pull

There were conflicts:

Auto-merging src/app/models/budget-date.ts
CONFLICT (content): Merge conflict in src/app/models/budget-date.ts
Auto-merging src/app/components/timeline/timeline.component.ts
CONFLICT (content): Merge conflict in src/app/components/timeline/timeline.component.ts
Auto-merging src/app/components/timeline-date/timeline-date.component.ts
CONFLICT (content): Merge conflict in src/app/components/timeline-date/timeline-date.component.ts
Auto-merging src/app/components/expenses-log/expenses-log.component.ts
CONFLICT (content): Merge conflict in src/app/components/expenses-log/expenses-log.component.ts
Automatic merge failed; fix conflicts and then commit the result.

I merged the conflicts but I'm not not sure I merged the conflicts properly so I want to undo all the changes and redo the merge:

git status
On branch release-0.1
Your branch and 'origin/release-0.1' have diverged,
and have 1 and 2 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

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

Changes to be committed:

        modified:   src/app/components/expenses-log/expenses-log.component.html
        modified:   src/app/components/expenses-log/expenses-log.component.scss
        modified:   src/app/services/timeline/timline.service.ts

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

        both modified:   src/app/components/expenses-log/expenses-log.component.ts
        both modified:   src/app/components/timeline-date/timeline-date.component.ts
        both modified:   src/app/components/timeline/timeline.component.ts
        both modified:   src/app/models/budget-date.ts

How do I undo the changes and redo the merge?

matt
  • 659
  • 2
  • 8
  • 15
  • try `git revert -m 1 (Commit id of the merge commit)` ? – pwxcoo Jan 23 '19 at 02:39
  • Possible duplicate of [Undo git pull, how to bring repos to old state](https://stackoverflow.com/questions/1223354/undo-git-pull-how-to-bring-repos-to-old-state) – phd Jan 23 '19 at 05:23
  • https://stackoverflow.com/search?q=%5Bgit%5D+undo+pull – phd Jan 23 '19 at 05:23
  • 1
    Can we safely assume that you already tried (and ruled out, for some reason) to `git merge --abort`, as hinted here in the git output you quoted? Because it *would be* the standard way out. – Romain Valeri Jan 23 '19 at 08:46

2 Answers2

0

You can revert that merge with:

git revert -m <commit ID>

Also you can use the following approach

And you can do it in other way by using git reflog <branch> to find out where your branch was before the merge, and git reset --hard <commit_id> to restore the old revision (you will get back to this commit).

Then just you can push it back.

It should go easy.

Kunal Vohra
  • 2,703
  • 2
  • 15
  • 33
0

Kunal's two solutions are the main options to consider when your merge is effective and commited.

If, in the other hand, you have not yet completed the merge with a post-conflicts-fixing commit, just git merge --abort as hinted here in the git output you quoted.

It will reset your files in the state they were just before the merge command (and additionnally it won't clutter your branch history, contrary to a revert)

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61