A
A
aarifkhamdi2020-07-05 21:11:16
git
aarifkhamdi, 2020-07-05 21:11:16

How to make a tricky reset while saving commits?

I have branch 1 and branch 2.

I need to keep all the commits on branch 2, but make sure it matches branch 1 exactly.

It's basically git reset --hard, but I need to keep the commits. I would somehow magically calculate all the changes that need to be made in branch 2 in order to get exactly the same state as it is now in branch 1. And make a new commit to branch 2 to get the state as in branch 1.

Stumbled, but didn't come up with anything

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-07-05
@jcmvbkbc

I would somehow magically calculate all the changes that need to be made in branch 2 in order to get exactly the same state as it is now in branch 1. And make a new commit to branch 2 to get the state as in branch 1.

$ git checkout branch2 # перейти к ветке branch2
$ git reset --hard branch1 # скопировать в неё историю и текущее состояние ветки branch1
$ git reset --soft [email protected]{1} # восстановить историю ветки branch2, но не трогать текущее состояние
$ git commit -m 'magic commit' # закоммитить текущее состояние (равное разности branch2 -> branch1) в branch2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question