Подтвердить что ты не робот

Git: как переместить некоторые коммиты в новую ветку

Я работаю по прямой:

A---B---C---D---E---F (master:HEAD)

Теперь я хочу двигаться назад:

git checkout C

и переместить несколько последних коммитов в новую ветку:

Вариант 1:

          D---E---F (new:HEAD)
         /
A---B---C (master)

Вариант 2:

          F (new:HEAD)
         /
A---B---C (master)

Как переустановить вариант 1 и вариант 2?

4b9b3361

Ответ 1

Чтобы перейти от первой диаграммы (master = HEAD = F) к опции 1:

git branch new        # Make a 'new' branch pointing at HEAD, which is F
git reset --hard C    # Move master back to point at C
git checkout new      # Make HEAD follow new, and get F in the working tree

И от варианта 1 до варианта 2 (сбор, где выше это было снято),

git rebase -i master  # Start the process of re-jiggering this branch
# edit the commit list that opens up to only include F
# save and exit
# resolve potential conflicts from missing changes in D and E

Чтобы перейти непосредственно от начальной точки к опции 2:

git checkout -b new C  # Start the 'new' branch at C
git cherry-pick F      # Include F on it
git checkout master    # Switch back to master
git reset --hard C     # Rewind master to the earlier commit