0

Suppose that I have in master this log :


  • commit 6 (head)
  • commit 5
  • commit 4
  • commit 3
  • commit 2
  • commit 1

And I want to undo commit 3 so that I will have this log :


  • commit 6 (head)
  • commit 5
  • commit 4
  • commit 2
  • commit 1

If I do this with revert commit 3, I only have this in log :


  • commit 3 (head)
  • commit 2
  • commit 1

And it's not what I want.


Is there any solution for this issue please ?

sciderlive
  • 33
  • 1
  • 5

1 Answers1

0

You can try with rebase --onto. See an example:

$ git init
$ touch a
$ git add a
$ git commit -ma
$ touch b
$ git add b
$ git commit -mb
$ touch c
$ git add c
$ git commit -mc
$ git log
commit 849a63d70fee06aaa0022a1070071f5ac1ec7263 (HEAD -> master)
Author: Arkadiusz Drabczyk <adrabczyk@bigcorp.com>
Date:   Thu Apr 5 12:37:21 2018 +0200

    c

commit 43a6c0fa3959d1da88b89ab91dc29de1b5fb498e
Author: Arkadiusz Drabczyk <adrabczyk@bigcorp.com>
Date:   Thu Apr 5 12:37:16 2018 +0200

    b

commit 61d6d5fd8b0bca01acae2864b5175f01c156d860
Author: Arkadiusz Drabczyk <adrabczyk@bigcorp.com>
Date:   Thu Apr 5 12:37:11 2018 +0200

    a

We want to remove b:

$ git rebase -p --onto 43a6c0fa3959d1da88b89ab91dc29de1b5fb498e^ 43a6c0fa3959d1da88b89ab91dc29de1b5fb498e
$ git log
commit 88ea4078b221d7a5febf7cefefab789d97db86d8
Author: Arkadiusz Drabczyk <adrabczyk@bigcorp.com>
Date:   Thu Apr 5 12:37:21 2018 +0200

    c

commit 61d6d5fd8b0bca01acae2864b5175f01c156d860
Author: Arkadiusz Drabczyk <adrabczyk@bigcorp.com>
Date:   Thu Apr 5 12:37:11 2018 +0200

    a
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38