Search code examples
gitgithubgit-branchgit-commit

git returning to a commit and again get all together


I have commits like

12345
12346
12347

I want to get back tgo 12345 and work on this I will add new commits 23456, 23457, 23458 etc

then I may need to get 12345, 12346, 12347 and 23456, 23457, 23458 all together

Is this possible, what should be my steps to achieve this?


Solution

  • First try creating a new branch from the 12345 commit:

    git checkout -b new_branch 12345
    

    Then make your new commits 23456, 23457, 23458 on top of this branch. So, your two branches now look like this:

    old_branch: 12345 -- 12346 -- 12347
                      \
    new_branch:          23456 -- 23457 -- 23458
    

    If you want to later bring one set of commits from one branch into the other, you may try merging or rebasing.