All of lore.kernel.org
 help / color / mirror / Atom feed
* Git checkout multiple options issue
@ 2019-01-28 13:25 COLLOMB Joris -EXT
  2019-01-28 14:12 ` Randall S. Becker
  0 siblings, 1 reply; 8+ messages in thread
From: COLLOMB Joris -EXT @ 2019-01-28 13:25 UTC (permalink / raw)
  To: git

Hello,

Something like this:

git checkout -fb "branch_name"
(force branch creation and checkout it)

doesn't work (even if option a separated).

I don't know if this is consider as an issue, but here it is.

Thanks for reading,
Joris


________________________________
CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.

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

* RE: Git checkout multiple options issue
  2019-01-28 13:25 Git checkout multiple options issue COLLOMB Joris -EXT
@ 2019-01-28 14:12 ` Randall S. Becker
  2019-01-28 14:24   ` COLLOMB Joris -EXT
  0 siblings, 1 reply; 8+ messages in thread
From: Randall S. Becker @ 2019-01-28 14:12 UTC (permalink / raw)
  To: 'COLLOMB Joris -EXT', git

On January 28, 2019 8:25, COLLOMB Joris wrote:
> git checkout -fb "branch_name"
> (force branch creation and checkout it)
> 
> doesn't work (even if option a separated).
> 
> I don't know if this is consider as an issue, but here it is.

I think you might mean (which works on every platform I have):

git checkout -f -b "branch_name"

There is no provision for aggregating options into one. -fb (invalid) is not
the same as -f -b (valid).

Regards,
Randall

-- Brief whoami:
 NonStop developer since approximately 211288444200000000
 UNIX developer since approximately 421664400
-- In my real life, I talk too much.





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

* RE: Git checkout multiple options issue
  2019-01-28 14:12 ` Randall S. Becker
@ 2019-01-28 14:24   ` COLLOMB Joris -EXT
  2019-01-28 15:20     ` Randall S. Becker
  0 siblings, 1 reply; 8+ messages in thread
From: COLLOMB Joris -EXT @ 2019-01-28 14:24 UTC (permalink / raw)
  To: Randall S. Becker, git

Thanks for answer,

git checkout -f -b "branch_name"
gives me " Fatal: A branch named 'branch_name' already exists."

I understand that here the checkout is force, but not the branch creation.
The opposite option order doesn't work:

git checkout -b -f "branch_name"
gives me "Fatal:  '-f' is not a valid branch name."

Once again sorry if this is expected behavior.

[For clarity, I'm trying to move a branch and checkout it with one command.]

Regards,
Joris


-----Message d'origine-----
De : Randall S. Becker <rsbecker@nexbridge.com>
Envoyé : lundi 28 janvier 2019 15:12
À : COLLOMB Joris -EXT <joris.collomb-ext@alstomgroup.com>; git@vger.kernel.org
Objet : RE: Git checkout multiple options issue

On January 28, 2019 8:25, COLLOMB Joris wrote:
> git checkout -fb "branch_name"
> (force branch creation and checkout it)
>
> doesn't work (even if option a separated).
>
> I don't know if this is consider as an issue, but here it is.

I think you might mean (which works on every platform I have):

git checkout -f -b "branch_name"

There is no provision for aggregating options into one. -fb (invalid) is not the same as -f -b (valid).

Regards,
Randall

-- Brief whoami:
 NonStop developer since approximately 211288444200000000  UNIX developer since approximately 421664400
-- In my real life, I talk too much.





________________________________
CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.

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

* RE: Git checkout multiple options issue
  2019-01-28 14:24   ` COLLOMB Joris -EXT
@ 2019-01-28 15:20     ` Randall S. Becker
  2019-01-28 16:02       ` COLLOMB Joris -EXT
  2019-01-28 16:55       ` Kevin Daudt
  0 siblings, 2 replies; 8+ messages in thread
From: Randall S. Becker @ 2019-01-28 15:20 UTC (permalink / raw)
  To: 'COLLOMB Joris -EXT', git

On January 28, 2019 9:25, COLLOMB Joris wrote:
> -----Message d'origine-----
>> De : Randall S. Becker <rsbecker@nexbridge.com> Envoyé : lundi 28 janvier
>> 2019 15:12 À : COLLOMB Joris -EXT <joris.collomb-ext@alstomgroup.com>;
>> git@vger.kernel.org Objet : RE: Git checkout multiple options issue
>> 
>> On January 28, 2019 8:25, COLLOMB Joris wrote:
>> > git checkout -fb "branch_name"
>> > (force branch creation and checkout it)
>> >
>> > doesn't work (even if option a separated).
>> >
>> > I don't know if this is consider as an issue, but here it is.
>> 
>> I think you might mean (which works on every platform I have):
>> 
>> git checkout -f -b "branch_name"
>> 
>> There is no provision for aggregating options into one. -fb (invalid) is
not the
>> same as -f -b (valid).

> git checkout -f -b "branch_name"
> gives me " Fatal: A branch named 'branch_name' already exists."

Once the branch is created, you can't force its creation, because it is
already created. Just

git checkout "branch_name"

is sufficient at this point. git is correct to complain that you are trying
to create a branch that already exists.

git log --decorate --oneline --graph --all

will show you where your branch points in history at any given moment in
time in a convenient form.

> I understand that here the checkout is force, but not the branch creation.
> The opposite option order doesn't work:
> 
> git checkout -b -f "branch_name"
> gives me "Fatal:  '-f' is not a valid branch name."

In this case, you are asking git to create a branch named -f (the -b branch
option). Then "branch_name" becomes the reference that would be used to find
the commit that -f would have pointed to. However, -f is not a valid name
because it is an option and git is correct to reject it.

git checkout options are described here:
https://git-scm.com/docs/git-checkout

Regards,
Randall


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

* RE: Git checkout multiple options issue
  2019-01-28 15:20     ` Randall S. Becker
@ 2019-01-28 16:02       ` COLLOMB Joris -EXT
  2019-01-28 16:37         ` Randall S. Becker
  2019-01-28 16:55       ` Kevin Daudt
  1 sibling, 1 reply; 8+ messages in thread
From: COLLOMB Joris -EXT @ 2019-01-28 16:02 UTC (permalink / raw)
  To: Randall S. Becker, git

> Once the branch is created, you can't force its creation, because it is already created.

Sorry to not be agree, in the man page of git branch:

       -f, --force
           Reset <branchname> to <startpoint> if <branchname> exists already. Without -f git branch refuses to change an existing branch. In combination with -d (or --delete), allow
           deleting the branch irrespective of its merged status. In combination with -m (or --move), allow renaming the branch even if the new branch name already exists.

The behavior I was expecting with
git checkout -b -f "branch_name"
is a checkout on a forced branch creation at <startpoint>.

So the only solution for me is :
git branch -f "branch_name" && git checkout "branch_name"

So to resume:
- This is not an issue, just a divergence between my logic and git implementation.
- The message "Fatal:  '-f' is not a valid branch name." is maybe not optimal, and it may better be " Fatal:  you trying to force the creation of a branch. Please do "git branch -f" if you know what you're doing"

I still don't know if you understand me,
But I really appreciate that you take some time to answer me.

Regards,
Joris

-----Message d'origine-----
De : Randall S. Becker <rsbecker@nexbridge.com>
Envoyé : lundi 28 janvier 2019 16:20
À : COLLOMB Joris -EXT <joris.collomb-ext@alstomgroup.com>; git@vger.kernel.org
Objet : RE: Git checkout multiple options issue

On January 28, 2019 9:25, COLLOMB Joris wrote:
> -----Message d'origine-----
>> De : Randall S. Becker <rsbecker@nexbridge.com> Envoyé : lundi 28
>> janvier
>> 2019 15:12 À : COLLOMB Joris -EXT
>> <joris.collomb-ext@alstomgroup.com>;
>> git@vger.kernel.org Objet : RE: Git checkout multiple options issue
>>
>> On January 28, 2019 8:25, COLLOMB Joris wrote:
>> > git checkout -fb "branch_name"
>> > (force branch creation and checkout it)
>> >
>> > doesn't work (even if option a separated).
>> >
>> > I don't know if this is consider as an issue, but here it is.
>>
>> I think you might mean (which works on every platform I have):
>>
>> git checkout -f -b "branch_name"
>>
>> There is no provision for aggregating options into one. -fb (invalid)
>> is
not the
>> same as -f -b (valid).

> git checkout -f -b "branch_name"
> gives me " Fatal: A branch named 'branch_name' already exists."

Once the branch is created, you can't force its creation, because it is already created. Just

git checkout "branch_name"

is sufficient at this point. git is correct to complain that you are trying to create a branch that already exists.

git log --decorate --oneline --graph --all

will show you where your branch points in history at any given moment in time in a convenient form.

> I understand that here the checkout is force, but not the branch creation.
> The opposite option order doesn't work:
>
> git checkout -b -f "branch_name"
> gives me "Fatal:  '-f' is not a valid branch name."

In this case, you are asking git to create a branch named -f (the -b branch option). Then "branch_name" becomes the reference that would be used to find the commit that -f would have pointed to. However, -f is not a valid name because it is an option and git is correct to reject it.

git checkout options are described here:
https://git-scm.com/docs/git-checkout

Regards,
Randall


________________________________
CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.

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

* RE: Git checkout multiple options issue
  2019-01-28 16:02       ` COLLOMB Joris -EXT
@ 2019-01-28 16:37         ` Randall S. Becker
  0 siblings, 0 replies; 8+ messages in thread
From: Randall S. Becker @ 2019-01-28 16:37 UTC (permalink / raw)
  To: 'COLLOMB Joris -EXT', git

On January 28, 2019 11:03, COLLOMB Joris wrote:
>> -----Message d'origine-----
>> De : Randall S. Becker <rsbecker@nexbridge.com> Envoyé : lundi 28 janvier
>> 2019 16:20 À : COLLOMB Joris -EXT <joris.collomb-ext@alstomgroup.com>;
>> git@vger.kernel.org Objet : RE: Git checkout multiple options issue
>> 
>> On January 28, 2019 9:25, COLLOMB Joris wrote:
>> > -----Message d'origine-----
>> >> De : Randall S. Becker <rsbecker@nexbridge.com> Envoyé : lundi 28
>> >> janvier
>> >> 2019 15:12 À : COLLOMB Joris -EXT
>> >> <joris.collomb-ext@alstomgroup.com>;
>> >> git@vger.kernel.org Objet : RE: Git checkout multiple options issue
>> >>
>> >> On January 28, 2019 8:25, COLLOMB Joris wrote:
>> >> > git checkout -fb "branch_name"
>> >> > (force branch creation and checkout it)
>> >> >
>> >> > doesn't work (even if option a separated).
>> >> >
>> >> > I don't know if this is consider as an issue, but here it is.
>> >>.
>> >> I think you might mean (which works on every platform I have):
>> >>
>> >> git checkout -f -b "branch_name"
>> >>
>> >> There is no provision for aggregating options into one. -fb (invalid)
>> >> is
>> not the
>> >> same as -f -b (valid).
>> 
>> > git checkout -f -b "branch_name"
>> > gives me " Fatal: A branch named 'branch_name' already exists."
>> 
>> Once the branch is created, you can't force its creation, because it is already
>> created. Just
>> 
>> git checkout "branch_name"
>> 
>> is sufficient at this point. git is correct to complain that you are trying to
>> create a branch that already exists.
>> 
>> git log --decorate --oneline --graph --all
>> 
>> will show you where your branch points in history at any given moment in
>> time in a convenient form.
> 
>> > I understand that here the checkout is force, but not the branch creation.
>> > The opposite option order doesn't work:
>> >
>> > git checkout -b -f "branch_name"
>> > gives me "Fatal:  '-f' is not a valid branch name."
>> 
>> In this case, you are asking git to create a branch named -f (the -b branch
>> option). Then "branch_name" becomes the reference that would be used to
>> find the commit that -f would have pointed to. However, -f is not a valid
>> name because it is an option and git is correct to reject it.
>> 
>> git checkout options are described here:
>> https://git-scm.com/docs/git-checkout

>> > Once the branch is created, you can't force its creation, because it is
>> already created.

> Sorry to not be agree, in the man page of git branch:
> 
>        -f, --force
>            Reset <branchname> to <startpoint> if <branchname> exists already.
> Without -f git branch refuses to change an existing branch. In combination
> with -d (or --delete), allow
>            deleting the branch irrespective of its merged status. In combination
> with -m (or --move), allow renaming the branch even if the new branch name
> already exists.
> 
> The behavior I was expecting with
> git checkout -b -f "branch_name"
> is a checkout on a forced branch creation at <startpoint>.
> 
> So the only solution for me is :
> git branch -f "branch_name" && git checkout "branch_name"
> 
> So to resume:
> - This is not an issue, just a divergence between my logic and git
> implementation.
> - The message "Fatal:  '-f' is not a valid branch name." is maybe not optimal,
> and it may better be " Fatal:  you trying to force the creation of a branch.
> Please do "git branch -f" if you know what you're doing"

A few things:

1. Please put your responses at the end, by convention, for this distribution list so that I don't have to reformat the message each time 😉
2. You cannot assume that a flag in one command is going to do the same thing in another command. -f in checkout means one thing. -f in branch means something different. It is dangerous to conflate the meaning of flags between commands.
3. git branch -f is used to force a branch move on a branch that you do not have checked out, so mixing these is semantically incorrect. git branch -f will deliberately fail if you try to use it on the branch that is checked out. This is correct behaviour.
4. git checkout -f means to do the checkout even if the HEAD and working index do not match and has nothing to do with branch creation. These are entirely different meanings and must not be "blended" into one concept.
5. Your expectation of the functionality is different from what git is providing.

git checkout -b name creates a branch. The -f flag, which deals with index vs. HEAD, really has no usefulness with what you are trying to do. Perhaps we should throw an error saying -f and -b make no sense when used together, but I suspect there is a subtle reason for keeping that capability. It is NOT what you are intending.

git checkout -b -f is a SYNTAX error on part of the operator error, and git is correct to issue a Fatal error message about it. At best, git checkout -b "branch" -f is correct, but not meaningful.

If you are trying to script a situation where git checkout will work regardless of whether the branch exists or not, use git show-ref. Then your script can use git checkout -b "branch" if the branch does not exist, and git checkout -f "branch" if it does. You might get unpredictable results using -f anyway in this case because of the mismatch above.



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

* Re: Git checkout multiple options issue
  2019-01-28 15:20     ` Randall S. Becker
  2019-01-28 16:02       ` COLLOMB Joris -EXT
@ 2019-01-28 16:55       ` Kevin Daudt
  2019-01-28 17:29         ` Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Kevin Daudt @ 2019-01-28 16:55 UTC (permalink / raw)
  To: Randall S. Becker; +Cc: 'COLLOMB Joris -EXT', git

On Mon, Jan 28, 2019 at 10:20:02AM -0500, Randall S. Becker wrote:
> On January 28, 2019 9:25, COLLOMB Joris wrote:
> > -----Message d'origine-----
> >> De : Randall S. Becker <rsbecker@nexbridge.com> Envoyé : lundi 28 janvier
> >> 2019 15:12 À : COLLOMB Joris -EXT <joris.collomb-ext@alstomgroup.com>;
> >> git@vger.kernel.org Objet : RE: Git checkout multiple options issue
> >> 
> >> On January 28, 2019 8:25, COLLOMB Joris wrote:
> >> > git checkout -fb "branch_name"
> >> > (force branch creation and checkout it)
> >> >
> >> > doesn't work (even if option a separated).
> >> >
> >> > I don't know if this is consider as an issue, but here it is.
> >> 
> >> I think you might mean (which works on every platform I have):
> >> 
> >> git checkout -f -b "branch_name"
> >> 
> >> There is no provision for aggregating options into one. -fb (invalid) is
> not the
> >> same as -f -b (valid).
> 
> > git checkout -f -b "branch_name"
> > gives me " Fatal: A branch named 'branch_name' already exists."
> 
> Once the branch is created, you can't force its creation, because it is
> already created. Just
> 
> git checkout "branch_name"
> 
> is sufficient at this point. git is correct to complain that you are trying
> to create a branch that already exists.

git checkout -B exists, which does exactly that: force create a branch
at a new positon if it already exists.

Kind regards, Kevin

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

* Re: Git checkout multiple options issue
  2019-01-28 16:55       ` Kevin Daudt
@ 2019-01-28 17:29         ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2019-01-28 17:29 UTC (permalink / raw)
  To: Kevin Daudt; +Cc: Randall S. Becker, 'COLLOMB Joris -EXT', git

Kevin Daudt <me@ikke.info> writes:

> On Mon, Jan 28, 2019 at 10:20:02AM -0500, Randall S. Becker wrote:
>> On January 28, 2019 9:25, COLLOMB Joris wrote:
>> ...
>> > git checkout -f -b "branch_name"
>> > gives me " Fatal: A branch named 'branch_name' already exists."
>> 
>> Once the branch is created, you can't force its creation, because it is
>> already created. Just
>> 
>> git checkout "branch_name"
>> 
>> is sufficient at this point. git is correct to complain that you are trying
>> to create a branch that already exists.
>
> git checkout -B exists, which does exactly that: force create a branch
> at a new positon if it already exists.

Correct.

"git checkout -b/-B" is for lazy people to perform two things,
i.e. "creating a branch" and "checking the branch out", at the same
time.

If we did not allow "git checkout -b newbranch othercommit" and only
allowed "git checkout -b newbranch", i.e. to start a branch at the
current HEAD, then we could make "git checkout -f -b newbranch" to
mean "git checkout -B newbranch", because creating a branch at HEAD
and checking it out will not have a risk of overwriting local
changes, i.e. no need to force the "checking the branch out" part,
so the "--force" option can only mean "force creating the branch".

But because the new branch can begin at the commit whose tree
differs at a path that has local modifications, there needs a way to
tell the command which part, either "creating a branch" or "checking
the branch out", is being forced.  Hence, "-f" tells the "checking
out the branch" part to do the forcing (e.g. allowing local changes
to be overwritten), and "creating a branch" part is told to force
with the distinction between "-b" and "-B".




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

end of thread, other threads:[~2019-01-28 17:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 13:25 Git checkout multiple options issue COLLOMB Joris -EXT
2019-01-28 14:12 ` Randall S. Becker
2019-01-28 14:24   ` COLLOMB Joris -EXT
2019-01-28 15:20     ` Randall S. Becker
2019-01-28 16:02       ` COLLOMB Joris -EXT
2019-01-28 16:37         ` Randall S. Becker
2019-01-28 16:55       ` Kevin Daudt
2019-01-28 17:29         ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.