git撤销commit 并保存之前的修改
1.提交修改
# 先进行commit ,之后后悔啦 $ git commit -am "对首篇报告研究员字段改为author_name"
2.执行git log $ git log commit 3d6788f577faba5e1d408e372031c81beee79749 Author: yous <yous.com> Date: Thu Dec 14 10:08:36 2017 +0800 添加 commit 5029f0cc08cffb77f7358de7d5534e8f8eacb82e Author: yous <yous.com> Date: Thu Dec 14 09:52:39 2017 +0800 Revert "Revert "修改过程"" This reverts commit c81f785a06804f5f40b41dedd038efbe6d83f8a8.
3.可以看出,第一个是我刚刚commit的,要撤销,当然是选择第二个; 执行命令git reset --soft <commit> $ git reset --soft 5029f0cc08cf
4.查看是否撤回
$ git status
可以看出已经回撤啦,并且保留了修改。
二、--mixed
参数 –mixed $ git reset --mixed 5029f0cc08cff Unstaged changes after reset: M dataservice/app/ggservice/v1/event/service/InfoEventService.java yutao@yutao MINGW64 /d/sts/workspace/ggservice (yutao) $ git status On branch yutao Your branch is up-to-date with 'origin/yutao'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: dataservice/app/ggservice/v1/event/service/InfoEventService.java no changes added to commit (use "git add" and/or "git commit -a")
参数--soft
和--mixed
区别:
参数 | 区别 |
---|---|
--soft |
会将改动放在缓存区 |
--mixed |
不把改动放在缓存区 |
git reset –hard <commit_id>
这种方式,我个人是不推荐,它也是撤销,但是不会保留修改。
除非你确实是不想要刚刚commit
的内容,否则,这个操作会让你之前干的活,白干。
所以非常不推荐这个方式
转载于:https://blog.csdn.net/mentalitys/article/details/81079761