B is already in the commit history - what is the thought behind this???
Jan 27, 2023
6
Level 1
How to make old commit a new commit using GIT?
I have commits A->B->C->D.
I want B to be a newest version.
So I would end up with this A->B->C->D->B
Is it possible? To make older version of code newest version. But not losing any commits? Also code is already in Gihub and on server.
Level 70
@merrychristmas To make commit B the newest version, you can use the following commands:
- Checkout the commit that you want to be the new head (in this case, commit B)
git checkout <commit-hash-of-B>
- Create a new branch from this commit
git branch new-branch
- Checkout to your master branch
git checkout master
- Revert all commits that come after B.
git revert <commit-hash-of-C>..HEAD
This will create new commits that undo the changes made in commits C, D, and any other commits that come after B. This will effectively make B the newest version, while preserving the entire commit history.
1 like
Please or to participate in this conversation.