@@ -483,14 +483,11 @@ $ git checkout -b foo # or "git switch -c foo" <1>
483483$ git branch foo <2>
484484$ git tag foo <3>
485485------------
486-
487486<1> creates a new branch `foo`, which refers to commit `f`, and then
488487 updates `HEAD` to refer to branch `foo`. In other words, we'll no longer
489488 be in detached `HEAD` state after this command.
490-
491489<2> similarly creates a new branch `foo`, which refers to commit `f`,
492490 but leaves `HEAD` detached.
493-
494491<3> creates a new tag `foo`, which refers to commit `f`,
495492 leaving `HEAD` detached.
496493
@@ -519,84 +516,89 @@ to checkout these paths out of the index.
519516EXAMPLES
520517--------
521518
522- . The following sequence checks out the `master` branch, reverts
523- the `Makefile` to two revisions back, deletes `hello.c` by
524- mistake, and gets it back from the index.
525- +
519+ === 1. Paths
520+
521+ The following sequence checks out the `master` branch, reverts
522+ the `Makefile` to two revisions back, deletes `hello.c` by
523+ mistake, and gets it back from the index.
524+
526525------------
527526$ git checkout master <1>
528527$ git checkout master~2 Makefile <2>
529528$ rm -f hello.c
530529$ git checkout hello.c <3>
531530------------
532- +
533531<1> switch branch
534532<2> take a file out of another commit
535533<3> restore `hello.c` from the index
536- +
534+
537535If you want to check out _all_ C source files out of the index,
538536you can say
539- +
537+
540538------------
541539$ git checkout -- '*.c'
542540------------
543- +
541+
544542Note the quotes around `*.c`. The file `hello.c` will also be
545543checked out, even though it is no longer in the working tree,
546544because the file globbing is used to match entries in the index
547545(not in the working tree by the shell).
548- +
546+
549547If you have an unfortunate branch that is named `hello.c`, this
550548step would be confused as an instruction to switch to that branch.
551549You should instead write:
552- +
550+
553551------------
554552$ git checkout -- hello.c
555553------------
556554
557- . After working in the wrong branch, switching to the correct
558- branch would be done using:
559- +
555+ === 2. Merge
556+
557+ After working in the wrong branch, switching to the correct
558+ branch would be done using:
559+
560560------------
561561$ git checkout mytopic
562562------------
563- +
563+
564564However, your "wrong" branch and correct `mytopic` branch may
565565differ in files that you have modified locally, in which case
566566the above checkout would fail like this:
567- +
567+
568568------------
569569$ git checkout mytopic
570570error: You have local changes to 'frotz'; not switching branches.
571571------------
572- +
572+
573573You can give the `-m` flag to the command, which would try a
574574three-way merge:
575- +
575+
576576------------
577577$ git checkout -m mytopic
578578Auto-merging frotz
579579------------
580- +
580+
581581After this three-way merge, the local modifications are _not_
582582registered in your index file, so `git diff` would show you what
583583changes you made since the tip of the new branch.
584584
585- . When a merge conflict happens during switching branches with
586- the `-m` option, you would see something like this:
587- +
585+ === 3. Merge conflict
586+
587+ When a merge conflict happens during switching branches with
588+ the `-m` option, you would see something like this:
589+
588590------------
589591$ git checkout -m mytopic
590592Auto-merging frotz
591593ERROR: Merge conflict in frotz
592594fatal: merge program failed
593595------------
594- +
596+
595597At this point, `git diff` shows the changes cleanly merged as in
596598the previous example, as well as the changes in the conflicted
597599files. Edit and resolve the conflict and mark it resolved with
598600`git add` as usual:
599- +
601+
600602------------
601603$ edit frotz
602604$ git add frotz
0 commit comments