7

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.

flossfan
  • 10,554
  • 16
  • 42
  • 53

5 Answers5

4

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

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
1

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.

gregor
  • 4,733
  • 3
  • 28
  • 43
  • Thanks - will `git reset --hard HEAD` lose my previous commits, though? – flossfan Jan 03 '14 at 17:55
  • No. In your case `HEAD` references the `refs/heads/my-branch` and this should link to the last commit on the branch `my-branch` before the merge was started. Hence by resetting hard to `HEAD` you go back to the state of your last commit. – gregor Jan 03 '14 at 18:03
0

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>
Ederson
  • 133
  • 4
0

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.

ToDo
  • 754
  • 2
  • 17
  • 31
Xelian
  • 16,680
  • 25
  • 99
  • 152
-2

Open the conflict file and resolve removing the diffs.

Then:

git add . 
git commit -am "resolve conflicts"
git push origin master
John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
  • 1
    Push to master? But I only want to push to my branch, I don't want to push to master... can I push to my branch instead and leave master untouched? – flossfan Jan 03 '14 at 17:55
  • the `git add .` isn't necessary with the `-am`. or the `-a` isn't necessary with the `git add .` – emmagras Aug 12 '16 at 20:24