git撤销commit 并保存之前的修改
撤销并保留修改
参数 –soft
- # 先进行commit ,之后后悔啦
- $ git commit -am "对首篇报告研究员字段改为author_name"
执行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.
- commit c81f785a06804f5f40b41dedd038efbe6d83f8a8
- Author: yous <yous.com>
- Date: Thu Dec 14 09:52:22 2017 +0800
- Revert "修改"
- This reverts commit 5a1d18a032d8c9269613ff14593847f82043e627.
- commit 5a1d18a032d8c9269613ff14593847f82043e627
可以看出,第一个是我刚刚commit的,我要撤销,当然是选择第二个;
执行命令git reset --soft <commit>
$ git reset --soft 5029f0cc08cf
- 之后我们查看下,状态:
- $ git status
- On branch yutao
- Your branch is up-to-date with 'origin/yutao'.
- Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
- modified: dataservice/app/ggservice/v1/event/service/InfoEventService.java
可以看出已经回撤啦,并且保留了修改。
参数 –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的内容,否则,这个操作会让你之前干的活,白干。
所以非常不推荐这个方式。
git撤销commit 并保存之前的修改的更多相关文章
- Git撤销commit消息保留修改
有时候commit后发现commit信息错了或者是添加了不想commit的内容,但还没有push到远程仓库 这个时候 git reset --soft [commit_id] 就可以回滚到某一个com ...
- git撤销commit
请参考该文章:http://www.cnblogs.com/ningkyolei/p/5026011.html 场景: 不小心commit了一个不应该commit的修改,但是还没有push,想撤销那个 ...
- git撤销commit,但未git push的命令
在git push的时候,有时候我们会想办法撤销git commit的内容 1.找到之前提交的git commit的id git log 找到想要撤销的id 2.git reset –hard id ...
- git 撤销commit
如果不小心commit了一个不需要commit的文件,可以对其进行撤销. 先使用git log 查看 commit日志 commit 422bc088a7d6c5429f1d0760d008d86c5 ...
- 恢复git撤销commit的代码
使用git reset --hard 是将磁盘文件也删除 时候使用Git工作得小心翼翼,特别是涉及到一些高级操作,例如 reset, rebase 和 merge.甚至一些很小的操作,例如删除一个分支 ...
- idea使用 git 撤销commit 原
填写commit的id 就可以取消这一次的commit
- git 撤销提交的文件
一.问题 近期在使用git时遇到一个问题,就是在git上传文件时,将一个100兆的大文件添加到了git,并执行了push操作,这时在上传完毕后,会提示这个错误 Large files detected ...
- [转]git commit之后,想撤销commit
本文转自:http://www.cnblogs.com/lfxiao/p/9378763.html 写完代码后,我们一般这样 git add . //添加所有文件 git commit -m &quo ...
- git commit之后,想撤销commit
原文 写完代码后,我们一般这样 git add . //添加所有文件 git commit -m "本功能全部完成" 执行完commit后,想撤回commit,怎么办? 这样凉拌: ...
随机推荐
- 知识点---前端处理支持emoji表情
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Visual Studio 注释与取消注释快捷键
注释: 先CTRL+K,然后CTRL+C 取消注释: 先CTRL+K,然后CTRL+U
- Flipping an Image
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resu ...
- mysql链接服务器,update报错
select * from Openquery(MySQL, 'SELECT * FROM official.sys_hospital') 执行更新语句: ; 报错,错误信息: 链接服务器" ...
- windows10安装JIRA
windows10安装MySQL数据库 一.问题现象: cmd执行“mysql”命令,提示:ERROR 2003 (HY000): Can't connect to MySQL server on ' ...
- ExpandableListView解析JSON数据
效果图: 说明:刚开始使用这个控件我花费了3天的时间,但是一直都没有达到预期的效果,要么就是直接全部不显示,要么就是数据累加 ...
- Linux下普通IO文件操作函数---C语言
普通文件IO总结 FILE结构体 typedef struct { int level; /*填充/清空一级缓存*/ unsigned flag; /*文件状态指针*/ ...
- vue调试方法
vue调试方法有如下三种 1.chrome谷歌插件vue-devtools 2.console.log().console.error().alert().debugger 3.设置全局变量,分为两种 ...
- Git多账号配置,同一电脑多个ssh-key的管理
为什么有这种需求? 在我们开发过程中,可能会遇到使用同一台机器,既要向公司git服务器提交代码,也要向gitlib或者gitee等 git仓库提交代码,2个仓库设置的用户名信息,不一样,此时需要用到多 ...
- docker-2 tomcat
启动容器命令 docker run -d -p 8080:8080 -v /root/tomcat/webapps:/usr/local/tomcat/webapps -v /root/tomcat/ ...