RE: Git checkout multiple options issue
- From
- COLLOMB Joris -EXT <joris.collomb-ext@alstomgroup.com>
- Date
- Jan 28, 2019, 16:02 UTC
- Message-ID
- <HE1PR01MB3722F2B99E14165C952055BCA9960@HE1PR01MB3722.eurprd01.prod.exchangelabs.com>
- In-Reply-To
- <000701d4b71c$f3ba57f0$db2f07d0$@nexbridge.com>
> 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:
Show 21 quoted lines
> -----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.
Show 5 quoted lines
> 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.