How to Checkout Another Branch Commit in Git
How can checkout a commit of another branch in Git?
Suppose we’re working on master
, but we would like to checkout a specific commit of branch feature1
.
Checkout the appropriate branch
First, we want to checkout the branch whose commit we’d like to checkout.
git checkout feature1
Find the commit hash
We can find the correct commit hash in the terminal quite easily.
git log
We can list our commits on the current branch in reverse chronological order (most recent commits on top).
Based on the date and/or commit message, we should be able to find the string of letters and numbers after the word commit
.
Let’s highlight this hash and copy it to our clipboard.
Checkout the specific commit
Suppose our commit hash is 1a2b3c
.
Finally, we can checkout the specific commit from our feature1
branch into a new branch.
git checkout -b new-feature1 1a2b3c