From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=216.40.44.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796058702; b=k6rVDbiG4fp0Gy/BC+02JptQ2vNby3vf2wg0Gm6S+vsuvVBZZ2v5ZEkx59V7gaW65M/e Te1yZayHOZIF5oUzlqrlM2oqIcqxXMQ3Ep6o2KYrUJxboLkh7/N4U2nY0+hD/Ikro8hvf MrfqnUriE9f0Iaqibma48VaCL3zZfXWjgkfl2fNuBkaOOKrGCz71tZoxhoV2wdkYSaP8r +l5punKK3aXfmTY32AGdB8SJbXjSGHuX4J3HVebBbW2h9g9JaHEDYZ4yDXfI7zo02zqiN Br4P7Z09lNxoITdIAxjGV9E1tW39Q0d/cu9ZIE8YqgJPRisNVoHXY6Tg7wMRVQYJi1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796058702; 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-Rspamd-Queue-Id:X-Stat-Signature: X-Spam-Status:X-Rspamd-Server:X-Session-Marker:X-Session-ID: DKIM-Signature:X-HE-Tag:X-HE-Meta; bh=LCQavPmJroLB6aPpMl+tWdHaBeaH2lymfLoAYDTvHuE=; b=THcLEI4blwOqLE48Z2yXZtNUn/DQKtf1QXGQfzeJIkdIYYdhL8tC/P+Q/Pys+a2PLTMj KO0FplfaAVeGvK31iRMeGlKFJYbseJzlwvmrrux0tzHQVWGtZo2sZtkz8xMnB6RJqokmy xdZOnxm3NRMwXJ4tOFJNytQWI2I3ARnD/CVBmX1ArITI3ofKwpZ1QbDdwuWQh3XdeCWT+ igzR86WvOpDZkynvC8Ku8t8lvDKI09gaFZQOcEyRHEy+FbiQJoH1ouO4XypPUfvdlQteZ 7i+nxEw1TxSp8TtNxzyhLnNIiesj+ajRs5jrn0QA7bNxxkjaQ5cjy1whVos/Zx+9DKQ== 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=zo8Am+8V; arc=none smtp.remote-ip=216.40.44.17 Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) (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 13894606A31C for ; Mon, 30 Nov 2026 17:11:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 13894606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=goodmis.org header.i=@goodmis.org header.a=rsa-sha256 header.s=dkim1 header.b=zo8Am+8V Received: from omf19.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8FEFCA84B9; Mon, 30 Nov 2026 17:11:40 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf19.hostedemail.com (Postfix) with ESMTPA id 099EC20027; Mon, 30 Nov 2026 17:11:38 +0000 (UTC) Date: Mon, 30 Nov 2026 12:11:37 -0500 From: Steven Rostedt To: "D. Ben Knoble" Cc: Mirko Faina , git@vger.kernel.org Subject: Re: Prevent git reset --hard from losing data Message-ID: <20261130121137.2fbafcef@gandalf.local.home> In-Reply-To: References: <20261120145444.13061eb7@gandalf.local.home> <20261123160009.61bf0bce@gandalf.local.home> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 099EC20027 X-Stat-Signature: 9p5brp3eeerbq8pu8wxasbe83ujysj8b X-Rspamd-Server: rspamout03 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX1/a3rMz8+yPMJjsmKm/3Ml2ZvzEbqF4wbs= 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=LCQavPmJroLB6aPpMl+tWdHaBeaH2lymfLoAYDTvHuE=; b=zo8Am+8VMCdXVCK5URQDPKORTb6LqiLPcEQPxLSztXklxzo8+tFf6AoyfnrX4xJpB8qrs4TaBzdTHjRA/IY+RjhA5tV8UEOOpXBSmec5cp5b75FPoqkkcWKFnZPBX0N4LrL7+Z+1rx9ukh07GCpO8GT1bUjZomeXBmTBTvCeoQY= X-HE-Tag: 1796058698-463940 X-HE-Meta: U2FsdGVkX1+xzqRujyYAZaup+HmwQ6d1HCiDnpNLMGmIebRdDpRc+02T2wkR/lJkpybl51Fd/DcToCEYcPdYXnAUjvpNZBw4RolLNTAk9QowW8zigZdSwAt8Rqha32IZV03LqmXTOCnzkCfYJitOFpFpUNjJAFrkqYAr5H8HuQY6jCoAgcQ7pRD+r4xNZmr6b8Tr6l4F0Pzo8kuu4x48yl9sAJ99zLFkNFWQ72yaCdf+i4UzqQxdFFQCdHS/JGnw+kNmhkNE6rVtSv9dsuMHv/NFt07BfTxiwg2E/rKl32NPsPnb6nW1nZTK/745PnGLCQD19Rva5nFDAZRMp0NKC6CMqHGijqkn4DvjJdKqdJK0R9kQJtqPXEMc6fvyo6K4xXLKRYgx7PYyN1GXSm/0Mg== On Mon, 30 Nov 2026 09:54:55 -0500 "D. Ben Knoble" wrote: > Hi Steven, forgive the incoming question if it appears rude (I am > genuinely curious): I take no offense to this ;-) >=20 > On Mon, Nov 23, 2026 at 4:00=E2=80=AFPM Steven Rostedt wrote: > > > > On Fri, 20 Nov 2026 22:09:32 +0100 > > Mirko Faina wrote: > > =20 > > > You could just reset without the --hard option and restore what you > > > don't want to keep. Otherwise there's the --keep option that aborts t= he > > > reset if there's local changes, but you'd have to remember to type it > > > out every time. =20 > > > > I just tried it without the --hard and it reminded me why I never use t= hat. > > > > I just wanted to update one of my branches to one of my devel branches = and > > did a git reset without the hard and at the end it gives me: =20 >=20 > [a large diff between HEAD and working tree] Which is pretty much always the case when working on the Linux kernel. I have branches based on various rc releases and each one has thousands of changes between them. >=20 > Here a simple "git restore ." would restore the working tree to match > the index (which should be equivalent to HEAD), right? Hmm, I actually wasn't familiar with the restore option. Thanks! >=20 > I confess I'm very confused about why you use reset to update a branch > in the first place: you also wrote >=20 > > 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 comm= its > > 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 us= e, > > and do a "git reset --hard sha1" to convert the actual branch to the te= mp > > one. =20 >=20 > It seems to me you could instead do >=20 > git switch -c temp > =E2=80=A6 work, commit =E2=80=A6 > git switch branch-i-care-about > git merge temp >=20 > and edit the commit message as needed, or replace the merge with "git > cherry-pick ..temp" (or rebase "temp" before merging) if you prefer a > (simulated) fast-forward. >=20 > On the other hand, you could also do "git branch -f > branch-i-care-about temp", with the same kinds of "force flags can > lose work" caveats, though at least in that case you only risk losing > the commits referred to by branch-i-care-about@{1} when the GC runs > (as opposed to potentially losing uncommitted work with reset). >=20 > So, have you not considered those options? Or have you, and what about > them is unsuitable compared to git-reset? (Yes, I know the document > point of git-reset is to "Set 'HEAD' or the index to a known state," > so it's not totally out of the ordinary to use it to set a branch > [HEAD] to another branch [known state], but I find the pattern a bit > odd.) >=20 My workflow usually contains me working on several different topic branches at the same time. (I'll switch between them quickly, while one is being tested so I can work on another as the tests can last for 10s of minutes). These branches have a development, for-next, and urgent focus. The development is me trying all sorts of things. When I feel ready, I'll usually cherry pick to the for-next branch. When I checkout a for-next and cherry pick from the development, I sometimes realize I screwed something up and need to reset the branch back to its original state. If the work I was doing was a 'work-in-progress' I tend to create a branch to keep that work before doing the reset. Hence, something like this: $ git checkout trace/trace/for-next $ git cherry-pick trace/trace/devel SHA-1..SHA-2 [ work on it, rebase, etc ] Realize it isn't what I want: $ git branch trace/save-this-work $ git reset --hard What I sometimes forget, is that I didn't commit my last updates, so the branch with save-this-work doesn't include them. After the reset --hard, I lost what I had done. Over the years I just default to "reset --hard" all the time. This may be my own issue and I can accept that. In which case, I'll just create a "git-reset" script I use that adds the "--hard" option but does a git diff first and asks me if I want to continue if it finds any changes. -- Steve