Branch from a previous commit using Git

dole doug picture dole doug · May 12, 2010 · Viewed 708.4k times · Source

If I have n commits, how can I branch from the n-3 commit?

I can see the hash of every commit.

Answer

CB Bailey picture CB Bailey · May 12, 2010

You can create the branch via a hash:

git branch branchname <sha1-of-commit>

Or by using a symbolic reference:

git branch branchname HEAD~3

To checkout the branch when creating it, use

git checkout -b branchname <sha1-of-commit or HEAD~3>