首页 > 其他分享 >如何撤消当前提交

如何撤消当前提交

时间:2022-12-19 17:07:53浏览次数:57  
标签:reset git 当前 撤消 -- hard will 提交 commit

 

Careful: ​​git reset --hard​​ WILL DELETE YOUR WORKING DIRECTORY CHANGES. Be sure tostash any local changes you want to keep before running this command.

Assuming you are sitting on that commit, then this command will wack it...

git reset --hard HEAD~1

The ​​HEAD~1​​ means the commit before head.

Or, you could look at the output of ​​git log​​, find the commit id of the commit you want to back up to, and then do this:

git reset --hard <sha1-commit-id>

If you already pushed it, you will need to do a force push to get rid of it...

git push origin HEAD --force

However, if others may have pulled it, then you would be better off starting a new branch. Because when they pull, it will just merge it into their work, and you will get it pushed back up again.

If you already pushed, it may be better to use ​​git revert​​, to create a "mirror image" commit that will undo the changes. However, both commits will be in the log.


FYI -- ​​git reset --hard HEAD​​ is great if you want to get rid of WORK IN PROGRESS. It will reset you back to the most recent commit, and erase all the changes in your working tree and index.


Lastly, if you need to find a commit that you "deleted", it is typically present in ​​git reflog​​ unless you have garbage collected your repository.

​http://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git​

 



标签:reset,git,当前,撤消,--,hard,will,提交,commit
From: https://blog.51cto.com/u_15147537/5953041

相关文章

  • 四种常见的 POST 提交数据方式 专题
    定义和用法enctype属性规定在发送到服务器之前应该如何对表单数据进行编码。默认地,表单数据会编码为"application/x-www-form-urlencoded"。就是说,在发送到服务器之前,所有......
  • Git 修改已提交的commit注释
    两种情况:1.已经将代码push到远程仓库2.还没将代码push到远程仓库,还在本地的仓库中这两种情况下的修改大体相同,只是第一种情况最后会多一步下面来说怎么修改先搞清楚......
  • ajax 提交文件
    html页面:<formid="uploadForm"method="post"enctype="multipart/form-data"><label>选择文件</label><inputid="file"type="file"name="fil......
  • magento获取当前路径
    有时候我们需要获取当前路径来做一些事情,不废话了,直接上代码​​01​​​​<?php​​​​02​​​​$urlRequest​​​​​=Mage::app()->getFrontController......
  • (七) Mysql 之 binlog redolog 二阶段提交
    (一)背景知识:1binlogbinlog我们中文一般称作归档日志, 是MySQLServer层的日志,而不是存储引擎自带的日志,它记录了所有的DDL和DML(不包含数据查询语句)语句,而且是以......
  • 【NX二次开发】获取当前Dll文件名
    获取当前Dll文件名//获取当前Dll文件名stringGetModuleDLLFileName(){charszBuff[1024]={0};HMODULEhModuleInstance=_AtlBaseModule.GetModuleInsta......
  • 获取当前controller bean
    @AutowiredprivateRequestMappingHandlerMappingrequestMappingHandlerMapping;@AutowiredprivateApplicationContextapplicationContext;@AutowiredprivateHttpServ......
  • eclipse使用git提交项目
    eclipse使用git提交项目有2种方式:一种是git命令窗口,另一种是eclipse自带git插件(跟svn插件一样使用)一、使用git命令窗口提交项目1.首先官网下载git并安装,然后配置用户信息(任......
  • 如何修改IDEA提交的git代码的名字?
    解决办法:1.在Terminal终端中输入:gitconfiguser.name  来查看当前提交者的姓名。  2.修改成你想改的名字:gitconfig--globaluser.name"要修改的用户名......
  • 获取当前窗口的进程名 - 软件
    获取当前窗口的进程名---------------------------------------------生活的意义并不是与他人争高下,而在于享受努力实现目标的过程,结果是对自己行动的嘉奖。↑面的话......