Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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.

like image 818
flossfan Avatar asked Oct 02 '22 23:10

flossfan


1 Answers

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...

like image 188
Ramesh Rajendran Avatar answered Oct 15 '22 09:10

Ramesh Rajendran