Remix.run Logo
1718627440 a day ago

> Correct me I'm I'm wrong but I think were talking about using `git reset HEAD^` for splitting a commit.

I wasn't. I wanted to do the same as in the FAQ entry we are talking about, so I wanted to reset it to an older commit representing the same change (i.e. before an amend that we are now reverting). This is likely in a rebase, but we can always rebase later and only do the splitting now.

> With `--mixed`, it will also move the index back one step, so the index is empty (relative to HEAD)

Yes and this is the default (without any flag).

> That's what meant when I said "`git reset` by itself doesn't split a commit", because you need to do something like this:

That's what the `--soft` is for, then `git reset` does not touch the index.

> Just that additional steps are needed.

The only "additional" step required is specifying a commit message, which, as I said earlier, to me is a sensible default.

What I suggested applied on this case would be:

    git commit -m tmp
    git checkout @~
    git reset --soft previous-version # which you get from the reflog
    git commit -C @
    git rebase @~ branch-you-were-on --onto=@  # not of much use, when you only have a single commit you are throwing away in the next step, but when you are editing something earlier, this is likely what you want.
    git reset @~
If you want to do it with rebase:

    git commit -m tmp
    git rebase @~2 # break after first commit
    git reset --soft previous-version
    git commit -C @
    git rebase --continue
    git reset @~
More idiomatic, due to using the global list of todo commits:

    git rebase -i @~ --autostash # break after first commit
    git reset --soft previous-version
    git commit -C @
    git rebase --continue
You can drop the rebase, when it is really the commit in HEAD you want to split.

Actually what you can also do, but this doesn't use reset, is this:

    git rebase -i @~ --autostash
    # add as the first line:
    pick previous-version
    git rebase --continue
This will even do what you wanted and just reuse the same commit message without asking.

Honestly, what I do most of the time to split commits (when there isn't an older version I want to split it to) is to just amend and then unselect the changes I don't want with the cursor.