Condividi tramite


Resolve Git conflicts

An advantage to developing an app under version control is that many people can concurrently modify many different versions of the same codebase at the same time. However, this means that sometimes you must resolve conflicts before you can pull changes from the remote repository, or before you merge two branches. Even though conflicts can be frustrating, Visual Studio provides tools to help you resolve them.

Example of conflicts when you try to pull

For example, Raisa wants to push a change to a file. If any commits have been pushed since her last pull, she must pull them down before she can push her commit.

Fetch link on Commits page

She can view details about the incoming commit from Jamal and see that he has modified the same line of code that she modified.

Commit details

When she tries to pull, Visual Studio shows her the conflict.

Conflicts sometimes occur when you try to pull

Resolve content conflicts

Content conflicts are the most common type of conflict. In most cases, the Merge window is the easiest way to resolve a content conflict.

Using the Merge window to resolve a conflict

  1. Open the merge window.

  2. Select neither, one, or both of the check boxes on either side of the conflict to pull that content into the resolution.

  3. You can add code directly to the resolution if you need to.

  4. To move quickly among conflicts, choose Next Conflict (Keyboard: F9) or Previous Conflict (Keyboard: Shift + F9).

  5. When you are satisfied with the resolution, accept it.

Commit the merge

After you have resolved all the conflicts:

Commit Merge button on Resolve Conflicts page

  1. You can commit the merge.

  2. Or, if you cannot resolve all the conflicts (for example, if you don’t have the time or the information you need to proceed), you can undo all your resolutions.

If you decide to commit to the merge:

The Changes page with merge change ready to commit

After you commit, you then push your changes into the remote repository in your team project.

Pushing the commits

Q & A

Q: I can’t use Visual Studio to resolve some kinds of conflicts. How do I resolve them?

A: You can use the command prompt to resolve them. See Work from the Git command prompt, git-pull, and git-merge.

Q: I was blocked by the system because I don’t have permission. How do I get it?

A: Permission reference for Team Foundation Server