Friday, 24 November 2017

Create a New Branch from a History Commit

When we want to checkout a new branch we do:

git checkout -b name-of-new-branch 

This is actually shorten for:

git checkout -b name-of-new-branch current-branch 

That is to say, if we don't specify the starting point of this new branch, it starts by default from the current active branch. Since every commit has an SHA1 (Hash value) as its ID, we can use these IDs as the start pointer when we are using checkout command. For example:

git checkout -b name-of-new-branch 169d2dc 

In this way, the active branch is now switched to this new branch and things are the same with branch 169d2dc.

Note that we might need to use the long full SHA1 ID in case the short one conflicts with others.


ref:
https://liam0205.me/2015/04/29/git-checkout-history-version/

No comments:

Post a Comment