git merge --strategy=ours

Ветка в котороай я работал стала по сути мастер веткой. Однако настоящая мастер ветка не может быть смеджена с ней, так как в ней тоже есть изменения, но они мне не нужны. 

Задача. Все изменения из текущей ветки перенести в ветку мастер, при этом затереть все, что было сделано в мастере после ответвления это новой ветки. Другими словами сделать мою ветку мастером, а мастер удалить. (технически делается не так, но по результату похоже) 

Решение

Для этого идеально походит следующий набор команд 

git checkout better_branch
git merge --strategy=ours master    # keep the content of this branch, but record a merge
git checkout master
git merge better_branch             # fast-forward master up to the merge

https://stackoverflow.com/questions/2763006/make-the-current-git-branch-a-master-branch#

MERGE STRATEGIES

The merge mechanism (git merge and git pull commands) allows the backend merge strategies to be chosen with -s option. Some strategies can also take their own options, which can be passed by giving -X<option> arguments to git merge and/or git pull.

ours

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.

Ours
git merge -s ours branch1 branch2 branchN

The Ours strategy operates on multiple N number of branches. The output merge result is always that of the current branch HEAD. The "ours" term implies the preference effectively ignoring all changes from all other branches. It is intended to be used to combine history of similar feature branches.

Комментарии

Популярные сообщения из этого блога

Как узнать день недели для любой даты н.э.

Начало

Complete move of remote Git repository