Can I use “git checkout --” on two files?

前端 未结 6 1071
时光取名叫无心
时光取名叫无心 2020-12-10 10:00

Is it possible to use git checkout -- on multiple files in order to discard the changes?

If so how would I specify multiple files?

6条回答
  •  生来不讨喜
    2020-12-10 10:35

    List the two (or more) files in a file.

    With Git 2.25 (Q1 2020), a few more commands learned the "--pathspec-from-file" command line option, which I previously mentioned for git commit.

    That means you can use the old confusing git checkout command, or the new command (Git 2.23+) git restore with a list of files (to checkout/restore), instead of reaptinng multiple time the same command on different files.

    See commit a9aecc7, commit cfd9376, commit 8ea1189, commit 6fdc9ad, commit 1d022bb, commit bebb5d6, commit 21bb308 (03 Dec 2019) by Alexandr Miloslavskiy (SyntevoAlex).
    (Merged by Junio C Hamano -- gitster -- in commit 135365d, 25 Dec 2019)

    checkout, restore: support the --pathspec-from-file option

    Signed-off-by: Alexandr Miloslavskiy

    Decisions taken for simplicity:

    1. For now, --pathspec-from-file is declared incompatible with --patch, even when is not stdin. Such use case it not really expected.
    2. It is not allowed to pass pathspec in both args and file.

    you must specify path(s) to restore block was moved down to be able to test for pathspec.nr instead, because testing for argc is no longer correct.

    git switch does not support the new options because it doesn't expect arguments.


    With Git 2.26 (Q1 2020) adds more tests.

    See commit f94f7bd (30 Dec 2019) by Alexandr Miloslavskiy (SyntevoAlex).
    (Merged by Junio C Hamano -- gitster -- in commit 96aef8f, 30 Jan 2020)

    t: add tests for error conditions with --pathspec-from-file

    Suggested-By: Phillip Wood Signed-off-by: Alexandr Miloslavskiy Signed-off-by: Junio C Hamano

提交回复
热议问题