flossfan
flossfan

Reputation: 10854

git pull origin master gives merge conflict: what should I do?

I'm working on a branch (my-branch) that I created from master.

$ git checkout -b my-branch

I edited some files, and then checked them into the new branch:

$ git commit -a -m 'Add new feature'

Then I pulled from master (I'm not completely sure why I did this, or if it's good practice):

$ git pull origin master 

But pulling gave me lots of error messages:

   From github.com
 * branch            master     -> FETCH_HEAD
Auto-merging styles/common/module_more_info.scss
CONFLICT (add/add): Merge conflict in styles/common/module_more_info.scss
Auto-merging app/support/stagecraft_stub/responses/cloud.json
CONFLICT (content): Merge conflict in app/support/stagecraft_stub/responses/cloud.json
Auto-merging app/support/backdrop_stub/response_fetcher.js
CONFLICT (content): Merge conflict in app/support/backdrop_stub/response_fetcher.js
Automatic merge failed; fix conflicts and then commit the result.
vagrant@pp-development-1:/var/apps/spotlight$ git status

Running git status now shows lots of changed files:

# On branch my-branch

# Changes to be committed:
#
#       modified:   CONTRIBUTING.md
#       modified:   README.md
#       modified:   app/appBuilder.js
[lots more files]
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both modified:      app/support/backdrop_stub/response_fetcher.js
#       both modified:      app/support/stagecraft_stub/responses/cloud.json
#       both added:         styles/common/module_more_info.scss

Firstly, what has happened, and secondly, what do I do?

If I try to see what the differences are in any of the upper list of files, I get empty output, which is confusing (why does it want me to commit the file if there are no diffs?):

$ git diff CONTRIBUTING.md
$

Should I review the three files that are under Unmerged paths, and then commit this as a merge commit? UPDATE: Most importantly, can I then push it to my branch without messing up the master branch?

I don't seem to be able to roll back the last commit.

Upvotes: 9

Views: 30857

Answers (5)

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38683

Don't use merge tool, because it will be confused to you. Please take a backup your current code and revert your changes in current branch. Then checkout your master (dev), get latest then rewrite your changes, then push.

First you need to type gitk --all in your github for which branch will currently open by shown top side

then you need to revert that or rebase your code with your server latest code:

then command the following steps to push your branch to server master.

git status

git add .

git status

git commit -a -m "Comments"

git push origin yourbranchname

That's all...

Upvotes: 4

Xelian
Xelian

Reputation: 17208

So first configure your merge tool. I propose to install this

  • Now your changes are in conflict with the remote ones and you have to resolve the conflicts. Do for every file:

    • git merge tool

    • Save the file.

Now you said to git that you know that there were conflicts but you want to resolve them in the way you did it using merge tool. So the conflicts are now resolved.

git status

Now you have to commit the resolved files and then to push them.

PS. Another approach is to stash your changes instead of a commit then to pull from the origin and then to pop your stashes.

git stash save
git pull
git stash pop
git commit
git pull

But from what I read if you are sure for your changes you have to commit them as you did and then to merge them. Merging is very often and you have to know how to handle it.

Upvotes: 0

user3153632
user3153632

Reputation: 32

Open the conflict file and resolve removing the diffs.

Then:

git add . 
git commit -am "resolve conflicts"
git push origin master

Upvotes: -2

Ederson
Ederson

Reputation: 133

What may have happened is that:

  1. Some one else was editing or merged it's code with Master.
  2. You have a different charset from the last user who edited Master.

The solution is:

git mergetool <you can left here blank your choose a mergetool from those you have installed in your machine>

Upvotes: 0

gregor
gregor

Reputation: 4833

Basically, yes. git mergetool might be of some assistance. It simply opens a merge tool with the files that need your attention and afterwards adds them to the index. With a simple git commit you can create the merge conflict.

You can always go back to the state before your pull by executing git reset --hard HEAD.

Upvotes: 1

Related Questions