【转】git撤销commit

原文地址:http://zhyq0826.iteye.com/blog/1671638

如果不小心commit了一个不需要commit的文件,可以对其进行撤销。

 

先使用git log 查看 commit日志

 

 

Python代码   收藏代码
  1. commit 422bc088a7d6c5429f1d0760d008d86c505f4abe  
  2. Author: zhyq0826 <[email protected]>  
  3. Date:   Tue Sep 4 18:19:23 2012 +0800  
  4.   
  5.     删除最近搜索数目限制  
  6.   
  7. commit 8da0fd772c3acabd6e21e85287bdcfcfe8e74c85  
  8. Merge: 461ac36 0283074  
  9. Author: zhyq0826 <[email protected]>  
  10. Date:   Tue Sep 4 18:16:09 2012 +0800  

 

找到需要回退的那次commit的 哈希值,

 

git reset --hard commit_id 

 

 使用上面的命令进行回退

 

以下是豆瓣的

 

苍炎的日记

 

起因: 不小新把记录了公司服务器IP,账号,密码的文件提交到了git

方法:

    git reset --hard <commit_id>

    git push origin HEAD --force



其他:

    根据–soft –mixed –hard,会对working tree和index和HEAD进行重置:
    git reset –mixed:此为默认方式,不带任何参数的git reset,即时这种方式,它回退到某个版本,只保留源码,回退commit和index信息
    git reset –soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可
    git reset –hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容


    HEAD 最近一个提交
    HEAD^ 上一次
    <commit_id> 每次commit的SHA1值. 可以用git log 看到,也可以在页面上commit标签页里找到

猜你喜欢

转载自luchuan.iteye.com/blog/2247948