git switch --force vs --discard-changes: docs don't match behavior
- From
David Mandelberg <david@mandelberg.org>
- Date
- Mar 17, 2025, 16:50 UTC
- Message-ID
- <bce5a500-76c4-4462-8f99-b17a6f21f7ec@mandelberg.org>
Hi,
https://github.com/git/git/blob/683c54c999c301c2cd6f715c411407c413b1d84e/Documentation/git-switch.adoc?plain=1#L115-L124 describes --force as "An alias for `--discard-changes`."
At least on git 2.47.2 though[1], it looks like --force will force more things than --discard-changes:
$ touch Makefile
$ git switch master
error: The following untracked working tree files would be overwritten
by checkout:
Makefile
Please move or remove them before you switch branches.
Aborting
$ git switch --discard-changes master
error: Untracked working tree file 'Makefile' would be overwritten by merge.
$ git switch --force master
branch 'master' set up to track 'origin/master'.
Switched to a new branch 'master'Is this a bug in the code or documentation?
[1] I searched the mailing list to see if there were any relevant changes since then.