Git Mailing List Archive mirror
 help / color / mirror / Atom feed
* Proposal: adding --soft and --mixed options to git checkout
@ 2023-04-24 11:41 i o
  2023-04-24 21:32 ` Felipe Contreras
  0 siblings, 1 reply; 4+ messages in thread
From: i o @ 2023-04-24 11:41 UTC (permalink / raw)
  To: git@vger.kernel.org

I suggest adding `--soft` and `--mixed` options to `git checkout`, that act similarly to the corresponding options of `git reset`, i.e. `git checkout --soft <tree-ish>` should move the HEAD to <tree-ish> without affecting the working tree or index, and `git checkout --mixed <tree-ish>` should move the HEAD to <tree-ish> and update the index to match it without changing the working tree.

The difference between this and `git reset` of course would be that, unlike the latter, this doesn't 'drag' the current branch along with HEAD; instead the usual behaviour would apply depending on what exactly <tree-ish> is, i.e. `git checkout [--soft|--mixed] <commit>` would detach HEAD and point it to <commit>, whereas `git checkout [--soft|--mixed] <branch>` would move HEAD and switch from the current branch to <branch>.

I'm aware work arounds exist for these, something like:

    ```
    git checkout --detach
    git reset [--soft|--mixed] [<branch>|<commit>]
    git checkout [<branch>|<commit>]
    ```

so the aim here is really one of convenience by having this feature contained in a native option.

Another option that might be worth adding to `git checkout` is `--keep-index` (like the option in `git stash`), to move the HEAD to <tree-ish> and update the working tree to match it without changing the index.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Proposal: adding --soft and --mixed options to git checkout
  2023-04-24 11:41 Proposal: adding --soft and --mixed options to git checkout i o
@ 2023-04-24 21:32 ` Felipe Contreras
  2023-04-25  9:28   ` i o
  0 siblings, 1 reply; 4+ messages in thread
From: Felipe Contreras @ 2023-04-24 21:32 UTC (permalink / raw)
  To: i o, git@vger.kernel.org

i o wrote:
> I suggest adding `--soft` and `--mixed` options to `git checkout`, that act
> similarly to the corresponding options of `git reset`, i.e. `git checkout
> --soft <tree-ish>` should move the HEAD to <tree-ish> without affecting the
> working tree or index, and `git checkout --mixed <tree-ish>` should move the
> HEAD to <tree-ish> and update the index to match it without changing the
> working tree.

In my opinion it's pretty clear `--soft` and `--mixed` were terrible names and
I suggested in the past to rename them to `--no-stage` and `--stage` [1]. We
should not repeat those mistakes with `git checkout`.

If the new options were:

 * git checkout --no-stage
 * git checkout --no-work-tree

I think it would be pretty clear what is intended without explanation (as
opposed to `--soft` and `--mixed`).

> The difference between this and `git reset` of course would be that, unlike
> the latter, this doesn't 'drag' the current branch along with HEAD; instead
> the usual behaviour would apply depending on what exactly <tree-ish> is, i.e.
> `git checkout [--soft|--mixed] <commit>` would detach HEAD and point it to
> <commit>,

In my mind the whole point of `git checkout` is to update the work-tree, if the
command is not going to do that, then I don't think it should be `git
checkout`.

In theory all these three would do the same, correct?

 * git checkout --no-stage --no-work-tree <commit>
 * git reset --no-stage --detach <commit>
 * git update-ref --no-deref HEAD <commit>

My preference would be `git reset --no-stage --detach <commit>`.

> whereas `git checkout [--soft|--mixed] <branch>` would move HEAD
> and switch from the current branch to <branch>.

If we are going to switch the current branch, then `git switch` makes more
sense:

 * git switch --no-stage <branch>

Then, for the case of a commit we could do:

 * git switch --no-stage --detach <commit>

The advantage of limiting ourselves to `git switch` is that it doesn't have the
historical of `git checkout`/`git reset`.

Cheers.

[1] https://lore.kernel.org/git/20130829180129.GA4880@nysa/

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Proposal: adding --soft and --mixed options to git checkout
  2023-04-24 21:32 ` Felipe Contreras
@ 2023-04-25  9:28   ` i o
  2023-04-27 21:10     ` Felipe Contreras
  0 siblings, 1 reply; 4+ messages in thread
From: i o @ 2023-04-25  9:28 UTC (permalink / raw)
  To: Felipe Contreras, git@vger.kernel.org

Felipe Contreras wrote:
> In my opinion it's pretty clear `--soft` and `--mixed` were terrible names and
> I suggested in the past to rename them to `--no-stage` and `--stage` [1]. We
> should not repeat those mistakes with `git checkout`.

No problem with renaming, but this might also be an oppurtunity to reconsider the meaning of the two options to incorporate `--keep-index`. Maybe `--no-stage` should mean 'switch HEAD and the working tree but leave the staging area' (i.e. the equivalent of `--keep-index`), and `--no-work` should mean 'switch HEAD and the staging area but leave the working tree' (i.e. the equivalent of `--mixed`). `--soft` could then be achieved by combining these options: `--no-stage --no-work`, but it could be a worthwhile convenience to add a separate option for that (just moving the HEAD), so maybe `--head` or something like that.

> In my mind the whole point of `git checkout` is to update the work-tree, if the
> command is not going to do that, then I don't think it should be `git
> checkout`.

I suppose something similar could also be said about `git reset` though? Maybe this would support the general move away from those legacy commands towards the new set of commands, so putting these new options in `git switch` instead seems reasonable.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Proposal: adding --soft and --mixed options to git checkout
  2023-04-25  9:28   ` i o
@ 2023-04-27 21:10     ` Felipe Contreras
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Contreras @ 2023-04-27 21:10 UTC (permalink / raw)
  To: i o, Felipe Contreras, git@vger.kernel.org

i o wrote:
> Felipe Contreras wrote:
> > In my opinion it's pretty clear `--soft` and `--mixed` were terrible names and
> > I suggested in the past to rename them to `--no-stage` and `--stage` [1]. We
> > should not repeat those mistakes with `git checkout`.
> 
> No problem with renaming, but this might also be an oppurtunity to reconsider
> the meaning of the two options to incorporate `--keep-index`. Maybe
> `--no-stage` should mean 'switch HEAD and the working tree but leave the
> staging area' (i.e. the equivalent of `--keep-index`), and `--no-work` should
> mean 'switch HEAD and the staging area but leave the working tree' (i.e. the
> equivalent of `--mixed`). `--soft` could then be achieved by combining these
> options: `--no-stage --no-work`, but it could be a worthwhile convenience to
> add a separate option for that (just moving the HEAD), so maybe `--head` or
> something like that.

Of course, many options could be considered, but unfortunately the outcome will
be the same regardless of the consensus: no change will happen. As you can see
that's what happened in that previous thread, regardless of the overwhelming
consensus.
 
> > In my mind the whole point of `git checkout` is to update the work-tree, if the
> > command is not going to do that, then I don't think it should be `git
> > checkout`.
> 
> I suppose something similar could also be said about `git reset` though?

I don't know. To me `git reset` is too vague. Resetting what? The "HEAD"? That
to me has no meaning whatsoever, as "HEAD" is git-only semantic invention that
roughly translates to "the current branch" (but not quite).

So with `git reset` we are "resetting the current branch"? That doesn't tell me
much.

> Maybe this would support the general move away from those legacy commands
> towards the new set of commands, so putting these new options in `git switch`
> instead seems reasonable.

I would rather change the semantics of `git checkout` and `git reset` but that
seems rather impossible.

So yeah, I would focus on what has a remote chance of actually get done.

Cheers.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-27 21:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-24 11:41 Proposal: adding --soft and --mixed options to git checkout i o
2023-04-24 21:32 ` Felipe Contreras
2023-04-25  9:28   ` i o
2023-04-27 21:10     ` Felipe Contreras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).