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

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
雷峰网
雷峰网
The Register - Security
The Register - Security
The Cloudflare Blog
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
I
InfoQ
博客园 - 三生石上(FineUI控件)
H
Help Net Security
博客园 - 司徒正美
Vercel News
Vercel News
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
B
Blog
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
L
LangChain Blog
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recorded Future
Recorded Future
小众软件
小众软件
Martin Fowler
Martin Fowler
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Apple Machine Learning Research
Apple Machine Learning Research
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
V
Visual Studio Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
V
V2EX
Blog — PlanetScale
Blog — PlanetScale

Sophie Alpert

There are no lossless transformations of natural-language text Deconstructing “services” I don’t want AI agents controlling my laptop Materialized views are obviously useful TODOs aren’t for doing Everyone is wrong about that Slack flowchart Hire me to empower and upskill your eng team How React Changed the Web Forever: A Documentary Fast and maintainable patterns for fetching from a database React Conf: “Building a Custom React Renderer” Why review code? Metrics by proxy Yak shaving and fixing Voice React Conf: “React Today and Tomorrow” Why we host conference talk dry runs React Podcast: Inside React Type errors with inference need stacks Observable programming React 16: an API-compatible rewrite Hi, I’m trans. Initializing on the main thread using dispatch_once A near-perfect oninput shim for IE 8 and 9 Using React to speed up the Khan Academy question editor What I did at Khan Academy, 2012 edition Preventing XSS attacks when embedding JSON in HTML
Rolling back to an old revision in Mercurial (like git reset)
Sophie Alpert · 2012-07-19 · via Sophie Alpert

Recently I’ve wanted the functionality of git reset --hard several times in Mercurial. Though Mercurial doesn’t provide an easy alternative and shies away from the idea of mutable history, there are a few ways to achieve something close. In this post, I’ll outline a few of them.

hg rollback

If you specifically want to undo your last commit, you can use

hg rollback

which will undo the commit (and doesn’t touch the working tree — you should be able to follow it with a hg revert --all or hg update -C if you want to throw away all your changes as well).

hg clone -r

Suppose you want to reset your repository called giraffe to revision 77182fb7451f. If you cd into the parent directory and run

hg clone -r 77182fb7451f giraffe new-giraffe
cp giraffe/.hg/hgrc new-giraffe/.hg/

then you’ll end up with new-giraffe, a repository at revision 77182fb7451f. (The cp is necessary to ensure that new-giraffe paths (like git’s “remotes”) correctly point to the origin repo instead of to the giraffe folder as it would by default.)

This is faster than recloning from the internet because it only copies files locally on your disk (and on many systems, hard-links them to save even more time and space), but can still be really time-consuming if your repository is large.

hg strip

If you want to do more complicated things with modifying the commit history (which is somewhat frowned on in the hg world, by the way), first enable the Mercurial Queues extension by adding the following lines to your .hgrc (there’s no need to specify a path after the equals sign):

[extensions]
mq =

This gives you (among other useful things) the hg strip command to completely remove a changeset and all of its descendants from a repository. Thus you can use a command like

hg strip 1cc72d33ea76

if 1cc72d33ea76 is the first “bad” changeset in your repository that you want to remove.

Unfortunately, it’s often hard to remove exactly the right changesets using this method and it’s all too easy to end up with multiple heads (which you can view using hg heads), requiring tedious repeated application of hg strip before you can get to where you want to be with no extra heads.

hg strip using revsets

Using hg revsets, a Mercurial feature that I just learned about, you can delete all the ancestors of tip which are not ancestors of the revision you want to revert to, using a command like:

hg strip "ancestors(tip) and not ancestors(77182fb7451f)"

Make sure to first run

hg log -r "ancestors(tip) and not ancestors(77182fb7451f)"

which will show you all the changesets that hg strip would remove, so you can make sure you don’t irreparably harm your commit history (because you have backups… right?).

Hopefully this was helpful — let me know if there’s any way to make this easier that I’m missing.