On Mon, 30 Nov 2026 09:54:55 -0500 "D. Ben Knoble" <ben…@gmail.com> wrote:
> Hi Steven, forgive the incoming question if it appears rude (I am > genuinely curious):
I take no offense to this ;-)
> > On Mon, Nov 23, 2026 at 4:00 PM Steven Rostedt <rost…@goodmis.org> wrote:
> > > > On Fri, 20 Nov 2026 22:09:32 +0100 > > Mirko Faina <mro…@delayed.space> wrote: > >
> > > 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 the > > > reset if there's local changes, but you'd have to remember to type it > > > out every time.
> > > > I just tried it without the --hard and it reminded me why I never use that. > > > > 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:
> > [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.
> > 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!
> > I confess I'm very confused about why you use reset to update a branch > in the first place: you also wrote >
> > 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.
> > It seems to me you could instead do > > git switch -c temp <some-useful-base> > … work, commit … > git switch branch-i-care-about > git merge temp > > 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. > > 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). > > 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.) >
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 <original-sha> 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