Oto Shavadze
Oto Shavadze

Reputation: 42803

Go back to some previous state, but keep all next commits in log too

I have branch with 3 commits:

A -> B -> C (HEAD, master)

Now, if I need go back to A commit, I can use git checkout A, but this loses B and C commits from log.

How can I go back to some log, but keep all next commits in log ?

Upvotes: 0

Views: 64

Answers (2)

Michael
Michael

Reputation: 5048

You can also revert all the commits up to the desired commit this would preserve them and remove whatever changes they made. (I think you can do this in one commit no need for a separate commit for each revert). See here on reverting multiple commits into one new commit:
How to revert multiple git commits?

Upvotes: 0

Maroun
Maroun

Reputation: 95998

You can branch from A, and keep the log as is in your current branch:

git checkout -b my_branch A

This will create my_branch branch, with HEAD pointing to A.

If you now check the log of the branch you created the commit from, you'll see A, B and C:

$ git log <original_branch>
C (HEAD)
B
A

Upvotes: 1

Related Questions