Я работал в прямой линии:
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?
Чтобы перейти от вашей первой диаграммы (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