Branch from a previous commit using Git

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

I can see the hash of every commit.


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 do this on github.com:

  • Go to your project.
  • Click on the "Commits".
  • Click on the <> ("Browse the repository at this point in the history") on the commit you want to branch from.
  • Click on the "tree: xxxxxx" up in the upper left. Just below the language statistics bar, you'll get the option to "Find or Create Branch" (just type in a new branch name there) 从之前的提交分支

  • If you are not sure which commit you want to branch from in advance you can check commits out and examine their code (see source, compile, test) by

    git checkout <sha1-of-commit>
    

    once you find the commit you want to branch from you can do that from within the commit (ie without going back to the master first) just by creating a branch in the usual way:

    git checkout -b <branch_name>
    
    链接地址: http://www.djcxy.com/p/37558.html

    上一篇: 如何通过eclipse搜索并替换两行(一起)?

    下一篇: 使用Git从之前的提交中分支出来