-3

I have git project like this below

% git --log

commit 39b6b1d894d0788fdfc09947e1a5f88bf962b142 (HEAD -> master, origin/master, origin/HEAD)
Author: whitebear man <whitebear@whitebearnoMacBook-Air.local>
Date:   Wed Nov 9 15:29:13 2022 +0900

    all

commit 2656df9fb80b5085b4e7a50032712b13e3c407c9
Author: whitebear man <whitebear@whitebearnoMacBook-Air.local>
Date:   Thu Oct 13 13:48:36 2022 +0900

    all

commit d72472d00c649fdc04805d10c856d729e114a014
Author: whitebear man <whitebear@whitebearnoMacBook-Air.local>
Date:   Wed Oct 12 18:23:28 2022 +0900

    all

commit 0878cd86de3a939e8c99e33676abcfe1cfd14daa
Author: whitebear man <whitebear@whitebearnoMacBook-Air.local>
Date:   Tue Oct 11 11:38:58 2022 +0900

    all

commit 21c78ba8cfb811e1ad7dfb035ef5236e619f5d53
Author: whitebear man <whitebear@whitebearnoMacBook-Air.local>
Date:   Mon Oct 10 15:55:48 2022 +0900

    all

commit 9568b4b53fd14febc1ed100efcc6d412d0668471
Author: whitebear man <whitebear@whitebearnoMacBook-Air.local>
Date:   Mon Oct 10 15:37:27 2022 +0900

    all

Now I want to roll back commit 21c78ba8cfb811e1ad7dfb035ef5236e619f5d53 and make new branch. However I want to keep the latest commit 39b6b1d894d0788fdfc09947e1a5f88bf962b142 as master.

I should rollback and make new branch?

or make new branch and rollback??

whitebear
  • 11,200
  • 24
  • 114
  • 237
  • 1
    The Git tag really just is a helpdesk tag, right... Can't believe my eyes when a 10K rep asks such a question and a 500K and 25K rep user answer it. Is you guys' search that broken? Have you tried anything? Are you looking for a branch, and/or an interactieve rebase? Hard reset? Cherrypick perhaps? But you've asked over a thousand questions, you should know how this site works by now. – CodeCaster Nov 21 '22 at 09:03
  • 1
    Does this answer your question? [Branch from a previous commit using Git](https://stackoverflow.com/questions/2816715/branch-from-a-previous-commit-using-git) – CodeCaster Nov 21 '22 at 09:05
  • 1
    `I want to roll back commit 21c78ba8cfb811e1ad7dfb035ef5236e619f5d53` roll back _to_ or revert? Since the commits you want and do not want are not sequencial, what do you want to do with the ones in between? Edit: Wat? How is that answer the one that answers what you asked? unclear question, -1. – AD7six Nov 21 '22 at 09:05

2 Answers2

3

You could just create a new branch from the 21c78ba8 commit:

git branch new_branch 21c78ba8
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

@Tim's answer is a good point if you don't really want to rollback. If, however, you really want/need to revert what was done in 39b6b1d894d0788fdfc09947e1a5f88bf962b142, this is the simplest way to do it:

git revert 39b6b1d894
eftshift0
  • 26,375
  • 3
  • 36
  • 60