0

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 ?

Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236
  • 2
    After you have "gone back to `A`", do you intend to return to `C` (or `master`) later? And what do you want to do when you are on `A`? Just sight-seeing? Fix a bug and commit the fix? Or did it turn out that `B` and `C` are not needed? – j6t Dec 01 '19 at 08:12
  • 2
    Are you really asking how to see the logs from one commit-ish whilst having a different commit-ish checked out? – AD7six Dec 01 '19 at 12:57

2 Answers2

1

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
Maroun
  • 94,125
  • 30
  • 188
  • 241
0

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?

Michael
  • 4,538
  • 5
  • 31
  • 58