[Git]checkout 指定版本

时间:2021-06-21 18:49:43

Task:知道commit号,如何checkout 指定版本

1. 切换到master: git checkout master

2. 下载最新代码:  git pull

3. 下载head: git checkout HEAD

4. 查看log找到需要的版本: git log

5. 根据header checkout : git checkout XXXXXX

 [root@hpc66- ebs]$ git branch
* consistencyCheck
master
[root@hpc66- ebs]# git checkout master
Switched to branch 'master'
[root@hpc66- ebs]# git branch
consistencyCheck
* master
[root@hpc66- ebs]# git checkout HEAD
[root@hpc66- ebs]# git log |more
commit e24385f84866f0010d3317164b23be9e6054f283
Merge: 31d7dc5 41ac93d
Author: wa357 <wa6@dd.com>
Date: Wed Apr :: + merge modify_election commit 41ac93d383abf2e3b83a2df1cd3c201877867d2d
Author: lij <lij@dd.com>
Date: Mon Apr :: + modify the position of calling commit 40b81hpc6685c7340106206fa171d0611767d40f93b
[root@hpc66- ebs]# git checkout e24385f84866f0010d3317164b23be9e6054f283
Note: checking out 'e24385f84866f0010d3317164b23be9e6054f283'. You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at e24385f... merge modify_election_datanode_algorithm
[root@hpc66- ebs]#
[root@hpc66- ebs]# git branch
* (detached from e24385f)
consistencyCheck
master

check out 指定的branch

 git clone git@git.com:XXXX.git
git branch
git branch -a //查看历史
git branch -d dev //删除本地分支
git checkout -b dev origin/dev //checkout 远程
git log //查看日志