惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Last Week in AI
Last Week in AI
IT之家
IT之家
A
About on SuperTechFans
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
V
Visual Studio Blog
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
Vercel News
Vercel News
博客园 - Franky
有赞技术团队
有赞技术团队
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
量子位
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog

博客园 - 黄铨

AutoHotKey 简易自动化脚本的一些资料 Powershell 主题美化学习过程 - 黄铨 - 博客园 [实战]如何对比两个数据库之间的变化 - 黄铨 - 博客园 [实战]分钟级简易数据库执行日志 发个老梗,关于GIT如何回退已经提交的COMMIT,以及如何撤销未完成的合并。 Hello, .NET微软技术广州俱乐部 F7 - Visual Studio - switch between aspx and "codebehind" Mac OS X El Capitan(10.11)显示隐藏文件命令失效解决方法 博文阅读密码验证 - 博客园 Move System Databases in MS SQL SERVER 部署Microsoft.ReportViewe 关于TFS强制undo他人check out 几段查看数据库表占用硬盘空间的tsql How to perform validation on sumbit only TFS 2012 Disable Multiple Check-out kill the vs2012 preview tabs 在Chrome Console中加载jQuery Using NuGet without committing packages to source control(在没有把包包提交到代码管理器的情况下使用NuGet进行还原 ) 关于asp.net网站下aux路径访问问题
undo/delete a commit on git
黄铨 · 2016-06-27 · via 博客园 - 黄铨

areful: git reset --hard WILL DELETE YOUR WORKING DIRECTORY CHANGES. Be sure to stash 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.