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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM