Macs, Modularity and More

Zach has been doing his work in the zIntegration branch, while Yasmin has been working in the yUI branch. Open up index. Good thing we have Yasmin. Helpfully, Git tells you above what file or files contain the merge conflicts.

Branching and Merging

What on earth did Git do to your file? Git puts both revisions into the file in your working copy, since it expects you to do the work yourself to resolve this conflict. It would be quite instructional to see the common ancestor for both of these child revisions, to figure out the intent behind each change. First, you need to return to the previous state of your working environment.

Two years of squash merge - DNSimple Blog

Reset your working environment with the following command:. This reverts your working environment back to match HEAD, which, in this case, is the latest commit of your current branch, zIntegration. Now, you can configure Git to show you the three-way merge data with the following command:.

Note : If you ever wanted to change back to the default merge conflict tagging, simply execute git config merge. To see the difference in the merge conflict output, run the merge again:.

Execute the git status command, and Git shows you its understanding of the current state of the merge:. Most of that output makes sense, but the last bit is rather odd: both modified: index. Why does Git think there is more than one? In this case, Git is talking about both branches that are modified. To see this in a bit more detail, you can add the -s --short and -b --branch options to git status to get a consolidated view of the situation:. Git responds with the following:.

The left column is your local branch, which currently is the mid-merge state of the original zIntegration branch mixed with the changes from the yUI branch. The right column is the remote branch. So this abbreviated git status command shows the following:. These files are considered unmerged because Git has halted partway through a merge, and put the onus on you to fix things up.

So edit index. Save your work and return to the command line. Execute the condensed version of git status -sb to see what Git thinks about your merge attempt:. There you are; one new file and one modified file. Commit those changes now, this time letting Git provide the merge message via Vim:. Type :wq inside of Vim to accept the preconfigured merge commit message, and Git dumps you back to the command line with a brief status, showing you that the merge succeeded:.

Now, open index. That looks quite good. First, delete the yUI branch:. Switch to the master branch:. Now, attempt a merge of the zIntegration branch:. Git takes you straight into Vim, which means the merge had no conflicts. Type :wq to save this commit message and complete the merge. Git responds with the results of the merge:. Note : The -D switch forces the local deletion of the branch regardless of its status.

The challenge for this chapter is straightforward: resolve another merge conflict. Xanthe has an old branch with some updates to the documentation; this work is in the xReadmeUpdates branch. You want to merge that work to master. The steps are as follows:. If you get stuck, or want to check your solution, you can always find the answer to this challenge under the challenge folder for this chapter. In practice, merge conflicts can get pretty messy. And it might seem that, with a bit of intelligence, Git could detect that adding HTML attributes to a tag is not really a conflict.

And there are, in fact, lots of tools, such as IDEs and their plugins, that are language-aware and can resolve conflicts like this easily, without making you make all the edits by hand. But no tool can ever replace the insight that you have as a developer, nor can it replace your intimate understanding of your code and its intent. So you need to stash the current state of your work somewhere, before you switch branches. And git stash , covered in the next chapter, does just that for you.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.

Merge Conflicts

At some point when working with a partner, you will get a merge conflict in git. This is fine and does not mean you are using git wrong or that your files are irrevocably broken. This document is meant to provide an overview of how to resolve your first or many merge conflicts.

Merge strategies

A conflict usually happens when both partners modify similar regions of a file. Let's see how this situation arises and see how to fix it. Suppose Gwen adds the helper prototype, then adds, commits, and pushes her change to the shared repo. He adds his prototype for mystery and has no problem adding and committing his change. But what happens when Pharell tries to push? This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: e. Big scary error message.

But this is not too worrisome. It just says someone else, in this case Gwen, has pushed before and Pharrell has to pull those changes before he can push his changes. So let's try that. Well, grumble.

More errors. Git noted that there is a conflict in test1. Note when we run git status it will list conflicted files as both modified: and tells us that we have unmerged paths. First, don't panic.