Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge errors

I have a git branch called 9-sign-in-out with perfectly working code, and I want to turn it into the master. I'm currently on the master branch.

$ git branch 9-sign-in-out * master 

I'm trying to switch to 9-sign-in-out branch, but it doesn't allow me to:

$ git checkout 9-sign-in-out app/helpers/application_helper.rb: needs merge config/routes.rb: needs merge error: you need to resolve your current index first 

Any idea how can I ignore all the master branch errors and turn the 9-sign-in-out branch into the master? Maybe git rebase? But I don't want to lose the code in 9-sign-in-out branch.

like image 287
Sayanee Avatar asked May 15 '11 05:05

Sayanee


People also ask

Why am I getting a merge conflict?

Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. You must resolve all merge conflicts before you can merge a pull request on GitHub.

How do I see merge conflicts?

To see the beginning of the merge conflict in your file, search the file for the conflict marker <<<<<<< . When you open the file in your text editor, you'll see the changes from the HEAD or base branch after the line <<<<<<< HEAD .


1 Answers

It's worth understanding what those error messages mean - needs merge and error: you need to resolve your current index first indicate that a merge failed, and that there are conflicts in those files. If you've decided that whatever merge you were trying to do was a bad idea after all, you can put things back to normal with:

git reset --merge 

However, otherwise you should resolve those merge conflicts, as described in the git manual.


Once you've dealt with that by either technique you should be able to checkout the 9-sign-in-out branch. The problem with just renaming your 9-sign-in-out to master, as suggested in wRAR's answer is that if you've shared your previous master branch with anyone, this will create problems for them, since if the history of the two branches diverged, you'll be publishing rewritten history.

Essentially what you want to do is to merge your topic branch 9-sign-in-out into master but exactly keep the versions of the files in the topic branch. You could do this with the following steps:

# Switch to the topic branch: git checkout 9-sign-in-out  # Create a merge commit, which looks as if it's merging in from master, but is # actually discarding everything from the master branch and keeping everything # from 9-sign-in-out: git merge -s ours master  # Switch back to the master branch: git checkout master  # Merge the topic branch into master - this should now be a fast-forward # that leaves you with master exactly as 9-sign-in-out was: git merge 9-sign-in-out 
like image 93
Mark Longair Avatar answered Sep 28 '22 04:09

Mark Longair