интерактивная перебазировка с --preserve-merges всех коммитов в текущей ветке - PullRequest
0 голосов
/ 02 июля 2018

Кажется, уже есть некоторые подобные вопросы, но ни один из них не является именно тем, что я хочу.

Допустим, у меня есть история коммитов, подобная этой

* xxxxxxxH (HEAD -> B) Latest commit
* (more commits)
* xxxxxxxG (B) More commits
*   xxxxxxxF Merge branch 'master' into B
|\  
| * xxxxxxxE (master) Another commit on master
| * (more commits here)
| * xxxxxxxD Commit on master
* | xxxxxxxC Another commit 
* | (more commits here)
* | xxxxxxxB First commit on branch A
|/  
* xxxxxxxA (master) some commit

Теперь я хочу переписать историю ветви A, возможно, слить или отредактировать некоторые коммиты, но я также хочу изменить первый коммит на ветви A, а также я хочу сохранить слияния, чтобы сохранить слияние master в А.

Сначала я интуитивно попробовал git rebase -i -p xxxxxxxB, но, очевидно, он не включал сам коммит xxxxxxxB. Итак, еще одна попытка была git rebase -i -p xxxxxxxB^, которая включала этот коммит, но теперь он фактически не сохранял слияния.

Другой вариант, который выглядел многообещающим, был --root, но этот начинается с самого первого коммита во всем хранилище, что тоже не то, что я хочу.

Есть ли способ сделать то, что я хочу?

1 Ответ

0 голосов
/ 02 июля 2018

Дольше, чем я считал разумным, я смог получить решение по irc:

git rebase -i -m -r firstCommitInBranch^ делает именно то, что мне нужно.

Из документации git:

   -r, --rebase-merges[=(rebase-cousins|no-rebase-cousins)]
       By default, a rebase will simply drop merge commits from the todo list, and put
       the rebased commits into a single, linear branch. With --rebase-merges, the
       rebase will instead try to preserve the branching structure within the commits
       that are to be rebased, by recreating the merge commits. Any resolved merge
       conflicts or manual amendments in these merge commits will have to be
       resolved/re-applied manually.
       (...)
       The --rebase-merges mode is similar in spirit to --preserve-merges, but in
       contrast to that option works well in interactive rebases: commits can be
       reordered, inserted and dropped at will.

и

   -m, --merge
       Use merging strategies to rebase. When the recursive (default) merge strategy is
       used, this allows rebase to be aware of renames on the upstream side.

Я также пропустил ту часть документации, в которой говорилось, что не следует использовать -p вместе с -i:

   -p, --preserve-merges
       Recreate merge commits instead of flattening the history by replaying commits a
       merge commit introduces. Merge conflict resolutions or manual amendments to merge
       commits are not preserved.

       This uses the --interactive machinery internally, but combining it with the
       --interactive option explicitly is generally not a good idea unless you know what
       you are doing (see BUGS below).
...