Skip to main content
Frecuentemente publicamos actualizaciones de nuestra documentación. Es posible que la traducción de esta página esté en curso. Para conocer la información más actual, visita la documentación en inglés. Si existe un problema con las traducciones en esta página, por favor infórmanos.

Esta versión de GitHub Enterprise se discontinuó el 2022-06-03. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener un mejor desempeño, más seguridad y nuevas características, actualiza a la última versión de GitHub Enterprise. Para obtener ayuda con la actualización, contacta al soporte de GitHub Enterprise.

Resolving a merge conflict using the command line

You can resolve merge conflicts using the command line and a text editor.

Merge conflicts occur when competing changes are made to the same line of a file, or when one person edits a file and another person deletes the same file. For more information, see "About merge conflicts."

Tip: You can use the conflict editor on GitHub Enterprise Server to resolve competing line change merge conflicts between branches that are part of a pull request. For more information, see "Resolving a merge conflict on GitHub."

Competing line change merge conflicts

To resolve a merge conflict caused by competing line changes, you must choose which changes to incorporate from the different branches in a new commit.

For example, if you and another person both edited the file styleguide.md on the same lines in different branches of the same Git repository, you'll get a merge conflict error when you try to merge these branches. You must resolve this merge conflict with a new commit before you can merge these branches.

  1. Abre la TerminalTerminalGit Bash.

  2. Navigate into the local Git repository that has the merge conflict.

    cd REPOSITORY-NAME
  3. Generate a list of the files affected by the merge conflict. In this example, the file styleguide.md has a merge conflict.

    $ git status
    > # On branch branch-b
    > # You have unmerged paths.
    > #   (fix conflicts and run "git commit")
    > #
    > # Unmerged paths:
    > #   (use "git add ..." to mark resolution)
    > #
    > # both modified:      styleguide.md
    > #
    > no changes added to commit (use "git add" and/or "git commit -a")
  4. Open your favorite text editor, such as Atom, and navigate to the file that has merge conflicts.

  5. To see the beginning of the merge conflict in your file, search the file for the conflict marker <<<<<<<. When you open the file in your text editor, you'll see the changes from the HEAD or base branch after the line <<<<<<< HEAD. Next, you'll see =======, which divides your changes from the changes in the other branch, followed by >>>>>>> BRANCH-NAME. In this example, one person wrote "open an issue" in the base or HEAD branch and another person wrote "ask your question in IRC" in the compare branch or branch-a.

    If you have questions, please
    <<<<<<< HEAD
    open an issue
    =======
    ask your question in IRC.
    >>>>>>> branch-a
    
  6. Decide si quieres mantener únicamente los cambios de tu rama, mantener únicamente los cambios de las demás ramas, o hacer un cambio nuevo, el cual puede incorporar cambios de ambas ramas. Borra los marcadores de conflicto <<<<<<<, =======, >>>>>>> y realiza los cambios que quieras en la fusión final. In this example, both changes are incorporated into the final merge:

    If you have questions, please open an issue or ask in our IRC channel if it's more urgent.
  7. Add or stage your changes.

    $ git add .
  8. Commit your changes with a comment.

    $ git commit -m "Resolved merge conflict by incorporating both suggestions."

You can now merge the branches on the command line or push your changes to your remote repository on GitHub Enterprise Server and merge your changes in a pull request.

Removed file merge conflicts

To resolve a merge conflict caused by competing changes to a file, where a person deletes a file in one branch and another person edits the same file, you must choose whether to delete or keep the removed file in a new commit.

For example, if you edited a file, such as README.md, and another person removed the same file in another branch in the same Git repository, you'll get a merge conflict error when you try to merge these branches. You must resolve this merge conflict with a new commit before you can merge these branches.

  1. Abre la TerminalTerminalGit Bash.

  2. Navigate into the local Git repository that has the merge conflict.

    cd REPOSITORY-NAME
  3. Generate a list of the files affected by the merge conflict. In this example, the file README.md has a merge conflict.

    $ git status
    > # On branch main
    > # Your branch and 'origin/main' have diverged,
    > # and have 1 and 2 different commits each, respectively.
    > #  (use "git pull" to merge the remote branch into yours)
    > # You have unmerged paths.
    > #  (fix conflicts and run "git commit")
    > #
    > # Unmerged paths:
    > #  (use "git add/rm ..." as appropriate to mark resolution)
    > #
    > #	deleted by us:   README.md
    > #
    > # no changes added to commit (use "git add" and/or "git commit -a")
  4. Open your favorite text editor, such as Atom, and navigate to the file that has merge conflicts.

  5. Decide if you want keep the removed file. You may want to view the latest changes made to the removed file in your text editor.

    To add the removed file back to your repository:

    $ git add README.md

    To remove this file from your repository:

    $ git rm README.md
     > README.md: needs merge
     > rm 'README.md'
  6. Commit your changes with a comment.

    $ git commit -m "Resolved merge conflict by keeping README.md file."
    > [branch-d 6f89e49] Merge branch 'branch-c' into branch-d

You can now merge the branches on the command line or push your changes to your remote repository on GitHub Enterprise Server and merge your changes in a pull request.

Further reading