首页  

git reset 版本回退     所属分类 git 浏览量 1269
git reset  改变 HEAD 的指向


note.txt 做两次修改分别commmit 

git log  --pretty=oneline  -5
c61e5df13f7bf518910af757bfdd27cc6ed31f44 20190828-16-05
735bb280d4861d0664aae98e76d73ff7e01015a6 20190828-16-03
64fd907c5c6082b2678fb46c6236de1cfcdfe9c0 revert and note.txt conflic
4d54684e134d48d99b8a0771e4f2e1fc36b28d7b note.txt add 2019-07-05 15:53:05
338536de39e4b76de01adc8512c2b16e683acfdd note.txt add 2019-07-05 15:51:45

将本地的状态回退到和远程的一样 
git reset --hard origin/master    

git reset --hard HEAD

回退到上一个版本
git reset --hard HEAD^

git log  --pretty=oneline  -5
735bb280d4861d0664aae98e76d73ff7e01015a6 20190828-16-03
64fd907c5c6082b2678fb46c6236de1cfcdfe9c0 revert and note.txt conflic
4d54684e134d48d99b8a0771e4f2e1fc36b28d7b note.txt add 2019-07-05 15:53:05
338536de39e4b76de01adc8512c2b16e683acfdd note.txt add 2019-07-05 15:51:45
192c09c1e5738988684fedc85a4c5b824ca1bbfc add note.txt


git status
On branch master
Your branch is ahead of 'origin/master' by 1 commits.

git log 无法看到 20190828-16-05 的提交记录

git reflog
735bb28 HEAD@{0}: reset: moving to HEAD^
c61e5df HEAD@{1}: reset: moving to c61e5df
735bb28 HEAD@{2}: reset: moving to HEAD^
c61e5df HEAD@{3}: commit: 20190828-16-05
735bb28 HEAD@{4}: commit: 20190828-16-03
64fd907 HEAD@{5}: checkout: moving from dev2 to master
5a3c138 HEAD@{6}: checkout: moving from master to dev2
64fd907 HEAD@{7}: clone: from https://gitee.com/dyyx/gitdemo.git

回到 20190828-16-05 版本


git reset --hard c61e5df
HEAD is now at c61e5df 20190828-16-05


git log  --pretty=oneline  -3
c61e5df13f7bf518910af757bfdd27cc6ed31f44 20190828-16-05
735bb280d4861d0664aae98e76d73ff7e01015a6 20190828-16-03
64fd907c5c6082b2678fb46c6236de1cfcdfe9c0 revert and note.txt conflic


git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.


HEAD指向当前版本,可以在各个历史版本之间穿梭, git reset --hard commit_id

git log 查看提交历史 

重返未来,用git reflog查看命令历史,确定要回到未来的哪个版本。 

git log 与  git reflog 的区别

git log 无法看到当前版本之后的版本 (未来版本)

上一篇     下一篇
约瑟夫环java实现

大数据SQL引擎

git diff 命令

redis集群方案

Mysql innodb 为何建议使用自增列作为主键

redis使用zset保留最近的数据