Re: PATCH: improve git switch documentation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/07/2021 21:45, Felipe Contreras wrote:
Martin wrote:
No. You can add all the explanation you want after "Resets the branch to
<head>.", but most of that explanation would be redundant, because as we
already agreed, there's no way to reset the head of a branch without
changing the branch.

By that logic a lot of explanations are redundant, because on some lever, if every user thinks far enough lots of things can be concluded.

From the docs (and similar on git checkout)
--force

    An alias for --discard-changes.
--discard-changes

    Proceed even if the index or the working tree differs from HEAD.
Both the index and working tree are restored to match the switching target. If --recurse-submodules is specified, submodule content is also restored to match the switching target. This is used to throw
away local changes.

If the working tree is made to match the target, then it can not retain local changes. That can be concluded.
Yet, it is explicitly mentioned.

Does it really hurt to mention it?
People overlook details that to others are blaring obvious.
I agree, we can not mention every potential possibility. But as a general rule, if data could be lost, then a mention (an explicit mention) should be made.

Yes, commits may be hold by the reflog. Except the reflog is optional. And more to the point, the reflog is unknown to plenty of people (never mind if they should know it, they do not) So the possibility of loss is rather real.

But anyway.
I brought forward my idea. I explained my reasoning.
If it (this part) is downvoted/rejected then that it how it is.


There still is the idea to replace the word "branch" by "branch name" in some parts of the git switch documentation.



So, I still ask:
- If "--force" to overwrite the work tree can clearly state that change
to files will be "thrown away".
- Then why can "force" re-using an existing branch name not do the same?

Because we would be forcing two things now.

Which 2 things?

The worktree overwriting is *not* forced by -C

    git switch -C b1 b2
    git checkout -B b1 b2

both give an error if the worktree has changed files.

This is only about what happens to the branch.

I.e we force the branchname to point to our new branch.
And that means the branchname no longe points to the old branch, and the
old branch therefore is removed.

It seems your proposal is to make `git switch -c --force b1 b2` be the same as
`git switch -C b1 b2`, but that would also make it the same as
`git switch -C --force b1 b2`. Therefore it would be forcing two things.

Or is your proposal something else?


No. I definitely want to keep those 2 apart from each other.

For each force-needing action, you should have to specify it's own force flag.

I do not want to change the behaviour on that part.

I only compared the
- doc of "-f" for worktree overwrites
with the
- doc -C for branch overwrites.

And I found that the former makes explicit mention of what can be lost, the latter leaves it to be concluded.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux