Как повторно объединить файл в Git? - PullRequest
29 голосов
/ 22 июня 2011

У меня есть 10 файлов, которые конфликтуют при объединении ветвей.Я разрешил все конфликты из 10 файлов (это заняло много времени).К сожалению, перед фиксацией я обнаружил, что один файл был объединен неправильно, и для этого файла нужно начать заново.: (

в Git, Как пометить файл, который был объединен, без объединения, другими словами, как повторно объединить этот файл?

1 Ответ

36 голосов
/ 22 июня 2011
git checkout -m <filename>

Это удалит его из индекса и вернет обратно в «конфликтующий» файл, в котором есть все маркеры, необходимые для последующего слияния.

На странице справки по git help checkout:

-m, --merge
    When switching branches, if you have local modifications to
    one or more files that are different between the current
    branch and the branch to which you are switching, the command
    refuses to switch branches in order to preserve your
    modifications in context. However, with this option, a
    three-way merge between the current branch, your working tree
    contents, and the new branch is done, and you will be on the
    new branch.

    When a merge conflict happens, the index entries for
    conflicting paths are left unmerged, and you need to resolve
    the conflicts and mark the resolved paths with git add (or git
    rm if the merge should result in deletion of the path).

    When checking out paths from the index, this option lets you
    recreate the conflicted merge in the specified paths.

(последнее предложение является наиболее важным).

Вот сообщение в блоге, которое описывает, почему оно было добавлено и как это невозможно с более старыми версиями git: http://gitster.livejournal.com/43665.html

...