Jump to content

Git - Merge Conflict

Hi P
Go to solution Solved by DevBlox,

Usually this happens when the file was changed on master and on the child, then an attempted merge. Could be that some silly change, like a space automatically removed, that snuck in to a commit on master (tends to happen if you use git add --all regularly), that child is not basing itself on. Now that the merge conflict is active you are in merging mode. Two ways to fix it right now:

  • Just solve the conflict and finish the merge. Remove the symbols (it shows you two possible options, local and incoming, you get to choose what you want), leave the changes you want to be in final merge, save. Then git add the file and git commit, you'll then have a merge commit, you're done.
  • If you don't want that on the master branch (some people/teams don't like having unclean merges in master, it is dangerous sometimes), abort the merge with git merge --abort. Then you checkout your child branch, and merge master into the child branch, this will merge the changes that child is not based on. Likely will cause a conflict, since your commits are there already. Solve it like the other case, get that merge commit. Then you will be able to do a clean merge to master.

I was just watching a tutorial on Git & GitHub, so I attempted to use the merge function and got an error and I can't figure out why

 

From Master branch

Spoiler

spacer.png

 

From Child branch

Spoiler

spacer.png

 

Merge Conflict

Spoiler

spacer.png

 

I seriously don't understand where I am messing up, am I using merge incorrectly? I thought it was literally to merge code into the same file

 

Please help, thank you :)

 

Link to comment
Share on other sites

Link to post
Share on other sites

Did you add that line to master before or after you created the child branch?

 

Git is essentially telling you: I've got two conflicting changes, which version is correct?

 

Git can merge changes automatically most of the time, but if changes on two branches happen on the same line its up to the developer to resolve this conflict

 

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Usually this happens when the file was changed on master and on the child, then an attempted merge. Could be that some silly change, like a space automatically removed, that snuck in to a commit on master (tends to happen if you use git add --all regularly), that child is not basing itself on. Now that the merge conflict is active you are in merging mode. Two ways to fix it right now:

  • Just solve the conflict and finish the merge. Remove the symbols (it shows you two possible options, local and incoming, you get to choose what you want), leave the changes you want to be in final merge, save. Then git add the file and git commit, you'll then have a merge commit, you're done.
  • If you don't want that on the master branch (some people/teams don't like having unclean merges in master, it is dangerous sometimes), abort the merge with git merge --abort. Then you checkout your child branch, and merge master into the child branch, this will merge the changes that child is not based on. Likely will cause a conflict, since your commits are there already. Solve it like the other case, get that merge commit. Then you will be able to do a clean merge to master.
Link to comment
Share on other sites

Link to post
Share on other sites

This means someone made a change to the same line of code and committed before you. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×