Article View: linux.kernel.git
Article #3498Re: Prevent git reset --hard from losing data
From: Steven Rostedt
Date: Fri, 20 Nov 2026 22:15
Date: Fri, 20 Nov 2026 22:15
53 lines
11350 bytes
11350 bytes
On Fri, 20 Nov 2026 14:02:16 -0800 Junio C Hamano <gitster@pobox.com> wrote: > Steven Rostedt <rostedt@goodmis.org> writes: > > > Too many times I do a "git reset --hard" in the wrong directory and end up > > losing uncommitted changes. Is there a way to add a configuration to have > > that command check if there's any uncommitted changes and ask if you really > > want to do the reset? > > I do not think so. Castrating an existing command without harming > others is a hard thing to do once the tool gains more than a few > hundred of users, and we probably have more users than that. I was hoping that there was just a way to add a hook that could run before executing the command. I wasn't suggesting that we make that the default. Just some kind of .gitrc that says "do this before executing X". > > I think you need to go to the root of the issue. Find out what made > you want to run "git reset --hard" and see if there are less drastic > solution to the same issue. And come up with a way to package that > less drastic solution in a form that would be useful to many people. Well, it's something I do on a daily basis and have for the last decade ;-) The reason I use git reset --hard is because I work on several topic branches and create development ones all the time. Sometimes I add commits across branches. I'll create a temp branch and work on it until I like it and then copy the sha1 of that branch, checkout the branch I want to use, and do a "git reset --hard sha1" to convert the actual branch to the temp one. > > That way, people would start using that newer solution and less > often be running "git reset --hard", reducing the risk. When > somebody really needs to do "git reset --hard" or a script that has > happily been running "git reset --hard", it will continue to do the > destructive thing as it was designed to, and everybody will be > happy. I could just make a script that would do what I want (do a git diff, and ask if there's any changes pending before doing a git reset --hard), and then train myself to use that instead. I simply emailed to see if there wasn't a way to do that type of hook before committing to that. There's a lot of things git does that I wish I knew before and I was wondering if this wasn't one of them. Thanks, -- Steve
Technical Details
Message-ID:
<20261120171528.3e6c3f5b@gandalf.local.home>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75990-linux-kernel-git=dewy.ruReferences:
<20261120145444.13061eb7@gandalf.local.home> <xmqqqzgfnouv.fsf@gitster.g>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75990-linux-kernel-git=dewy.ru From: rostedt@goodmis.org (Steven Rostedt) Newsgroups: linux.kernel.git Subject: Re: Prevent git reset --hard from losing data Date: Fri, 20 Nov 2026 17:15:28 -0500 Organization: Usenet Network Message-ID: <20261120171528.3e6c3f5b@gandalf.local.home> References: <20261120145444.13061eb7@gandalf.local.home> <xmqqqzgfnouv.fsf@gitster.g> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="3278114"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ZkbadQZWt95XeI8Rl5WEJg8vlIo= sha256:LSHtj7idAXbwC3HnRXfftEnBlkDXarT6qBFTmoaRdZM= sha1:nrj5MZN+delDknMAAbLlCbiAqDM= sha256:fNdZob6kCgtoQWcle7odKgCDR3fh1Lfedi0ro4RZPyI= List-ID: <git.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id F2DF3115AA5; Sat, 21 Nov 2026 01:17:58 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -1.95 X-Spam-Status: No, score=-1.95 tagged_above=-9999 required=6.31 tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=goodmis.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bCHRPXPJ5vP0; Sat, 21 Nov 2026 01:17:55 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-75990-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=goodmis.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 17E91115A8E; Sat, 21 Nov 2026 01:17:44 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id B2797A8AEA; Fri, 20 Nov 2026 22:15:35 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1795212935; b=YC8DJFmlZPfo7pv3Xx4kg393IQK4YaPZgRxo5FvAt46WQXBTLAsyoFA0FrXQm8+ZnZbB AvtdZsiermGUqE7Q/J/4Z5pNrtkijXMNlyeKvjorSiZJOG2Pl9YSVEkVv8r6GtZ8e83So YmN7lLb31ImUgopxGp6wXot69BdDc+vt//3xmLSIxeu5tLEk6KBNAo0AM0hM+XrJQ9gC5 i+8aISY5k36o2v0eDTEa+X2oyWCF+anKR6jkmcmeazIacSJD4cl75X93KTR1D8/ccGTBd L68/xiuJ3Phoya+RrczhyBmFiqDjgNV8kaL/VfdmGcOkRIs1mYlqTAWVeWcglGlUTNg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795212935; h=X-Original-To:Received:DMARC-Filter:Received:Received:Date:From:To: Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:X-Stat-Signature:X-Rspamd-Server: X-Rspamd-Queue-Id:X-Session-Marker:X-Session-ID:DKIM-Signature: X-HE-Tag:X-HE-Meta; bh=6hsxUyPAHnYTfuRL4Xi2aRrH5zuLLWsN4KyS5r8mSc8=; b=Iw7ojSnExRNwU9GEYy5NbIyvZrAaP2dTwtG2hhL6FM8W+8HTGZ8yfkeMIRAQsghUH+Ho eoiLKW12c62hsMtsClkYtRRE1B6kTmGu/VsBdk0ZqoYX/Lz3J7BKV0HpQVFWTz3KFGG1w tYbzdzAul01gbzKg8Xd3favUzmDVeHPwIMd7ERrjuuQZy+tHXoSti2CCq5NPljXO2rL8M AKQvQi5NSB4TUiEtRBkwBAiAgkYQdaAV5mP9kBSxxxCLOgv2w9KYCKY4BW8DF8QO7kSUN Bhv3EES447Tz5LXTBlLnE5toReVpZVDcEAnUUtgnND950aYYNNhDFL6D399fkGLt8/A== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=aGBptfID; dmarc=pass header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; arc=fail smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52E9460A2603; Fri, 20 Nov 2026 22:15:35 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=aGBptfID X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=216.40.44.13 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795212934; b=Sy+KzsBEg84FJ3ZQRyj/h09TUHYaumBDjQoAeifvnJjppKfDV2iKO1o60GT22CZimBEo NMo00baGWHS8pwkF5huMPnI0G+FFxLhjlvlUSxKhv7MyR/E5jran9ZG1EdVHWsqN5xnQY ypju02ZF71/9FC5qW/Bl3zJERGVOImN8NkOfTTHXU58+kMoPmIPTKhSXjxiijTFVJTOE+ Pp836I2YCFkfmmo7KJy/0QRP0TcACLVLE1ths2TamWnQFLn/sxL/Or/5E0qjP7B35M9OE AKGe5aEGsYWyzA0fFaCdX4o+23L6jxahuKWVGXSIe6zkCmu0Hb6HNgVcuP+xdDpkryw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795212934; h=DMARC-Filter:Received:Received:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding:X-Stat-Signature:X-Spam-Status: X-Rspamd-Server:X-Rspamd-Queue-Id:X-Session-Marker:X-Session-ID: DKIM-Signature:X-HE-Tag:X-HE-Meta; bh=6hsxUyPAHnYTfuRL4Xi2aRrH5zuLLWsN4KyS5r8mSc8=; b=PT8YapQEzpsS+l/PsNL/E3WVX0zxzipeeuETKw/ANPPOMVquz2/mYfW24arbIP5GTZew nt9AEX1JLaP7ugSUaC7oKge0PyNCp9NXEo1bUS5npiWoD5bAc42S8rOhA4C2PSCC1Pxns nvU0OYNbglOyEWYqaGp7CuMgPAEJ0UI+seeXdbNnCUlVRww6St2ce6n7NEkOgfJsq7d3j lsy0ykeOBcRAlRrQB9osyRm87/q4KHEAWGQHxOdwdcWQ5lAbEJ1UzUMOmo0oFTgXuCE9W FfXe09VV6zGBHP2ak5F63+ZgqeN2BhjbxpLq3XJ+MQ3nrJEX8Qlf4rCuhFe++bK72ew== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; dkim=pass header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=aGBptfID; arc=none smtp.remote-ip=216.40.44.13 X-Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87F7A606A68C for <git@vger.kernel.org>; Fri, 20 Nov 2026 22:15:32 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 87F7A606A68C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org X-Received: from omf06.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 56D02401CB; Fri, 20 Nov 2026 22:15:31 +0000 (UTC) X-Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf06.hostedemail.com (Postfix) with ESMTPA id CE56220010; Fri, 20 Nov 2026 22:15:29 +0000 (UTC) X-Cc: git@vger.kernel.org X-In-Reply-To: <xmqqqzgfnouv.fsf@gitster.g> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: git@vger.kernel.org X-List-Post: <mailto:git@vger.kernel.org> X-List-Help: <mailto:git+help@vger.kernel.org> X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:git+owner@vger.kernel.org> X-Precedence: list X-Stat-Signature: 6h8z3i9nqe4f7rhmnhwif73orp1igscd X-Rspamd-Server: rspamout04 X-Rspamd-Queue-Id: CE56220010 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX19icT3UWr6Wmq7/sQhZENOq2ZoTlDs1xiQ= X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=goodmis.org; h=date:from:to:cc:subject:message-id:in-reply-to:references:mime-version:content-type:content-transfer-encoding; s=dkim1; bh=6hsxUyPAHnYTfuRL4Xi2aRrH5zuLLWsN4KyS5r8mSc8=; b=aGBptfIDwsarclSHOvBUDn9icvIKxbfs+Mpz6t7Sh5oXTELGDG+N1kv12ksOg5GVEAnVkYSQErbhwHnxELtdD4/FkLs/7kMVK4DmnC5dN/irx29JPIJcaxzuBbWA0GpQr95rQZXKvEkruhANTMFtc326p9t89Ju+hicV9ijRImA= X-HE-Tag: 1795212929-99685 X-HE-Meta: U2FsdGVkX187ddYt6MWUhr0kM1moKawC4Hj+lPDLxqwCGY+IOUzl9jKYaUhl8xECNAJwFbR5aE/yKbkxby6ADI1poueNejs8EALUE2OGPE9Tag5VDgNh2OvsxfOZPR/SL7lisQu3yNzMBAJHb89uaTJBefrXmhO1adhj9hxaDM5xaU6lsL0QG4DLz86CcSqZTji17cXXO5tSpIH0kitK6qpDIm/aipoOm7h4VnXCmNddRqx9M3KskcDWG0lMuCBxGqiuQw3kwEHkJEKTfBNB0AdC9Qs4eDeiMdup0BzVxh6kTddEjax6/wJsLQUUFUSxwwJKzPqN9yjX0be02GrjWHX8BRIMLG6F9dAWfPTkaFkDvjQ8cOYRsZh6fHuB10x7+3xiL8RJTPVK/Sy90ekHOIwsItYnNE+R9U1apDqnbMMXUsIiW/h0+aZu+thbZ5HP