Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unstage all files and abandon merge

Tags:

git

I was running a simple merge and expecting no conflicts, and I ran git merge my_dev_branch

However I got a merge conflict which looked messy to resolve, and made me think that I wasn't clear on my branch history. Rather than resolve the conflict I would like to abandon the merge and go back to where I was before.

Two questions:

  1. Am I right in thinking that I could clean out my staging area by running git checkout HEAD <filename> on each file per this question and that this would amount to abandoning the merge?
  2. Is there a way I can do this in one command?
like image 634
Derek Hill Avatar asked Nov 07 '12 18:11

Derek Hill


People also ask

How do I Unstage merge changes?

You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.

How do I abandon a git merge?

You can use the git reset --merge command. You can also use the git merge --abort command.

How do you cancel merging if there are conflicts?

Use git-reset or git merge --abort to cancel a merge that had conflicts. Please note that all the changes will be reset, and this operation cannot be reverted, so make sure to commit or git-stash all your changes before you start a merge.

How do I undo an unfinished merge?

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 .


1 Answers

Try git merge --abort. Handy, eh?

like image 62
Jamey Sharp Avatar answered Sep 25 '22 14:09

Jamey Sharp