如何查看分支的提交版本git.例如,我的分支Dev有一个提交ad4f43af43e.我该如何查看该提交?不只是一个文件,而是整个分支.我在网上搜索并发现:git checkout <commit>,但它没有指定分支名称
谢谢.
sma*_*ber 16
git checkout <hash> # non named commit
git checkout <branch_name> # named commit
Run Code Online (Sandbox Code Playgroud)
上面的两行将HEAD指针放在给定的提交上.您应该知道分支名称是提交,除非您在该分支上添加新提交时它可以进化.
如果您想在分支Dev上设置分支,则ad4f43af43e可以执行此操作
git branch -f Dev ad4f43af43e
Run Code Online (Sandbox Code Playgroud)
小心!这很危险,因为你可能会失去提交
如果您希望从分支的特定提交中分支出来,请首先确保您在分支机构中,
git checkout dev
Run Code Online (Sandbox Code Playgroud)
现在我想从dev分支检出特定的提交123654到一个新的分支,同时保持头部在主分支上.
git checkout -b new-branch 123654
Run Code Online (Sandbox Code Playgroud)
您可以checkout到commit-sha那时,创建一个新的分支(说feature)从提交。
$ git checkout <commit>
$ git checkout -b feature # create a new branch named `feature` from the commit
# if you want to replace the current branch (say 'develop') with new created branch ('feature')
$ git branch -D develop # delete the local 'develop' branch
$ git checkout -b develop # create a new 'develop' branch from 'feature' branch
Run Code Online (Sandbox Code Playgroud)