@@ -483,14 +483,11 @@ $ git checkout -b foo # or "git switch -c foo" <1>
483
483
$ git branch foo <2>
484
484
$ git tag foo <3>
485
485
------------
486
-
487
486
<1> creates a new branch `foo`, which refers to commit `f`, and then
488
487
updates `HEAD` to refer to branch `foo`. In other words, we'll no longer
489
488
be in detached `HEAD` state after this command.
490
-
491
489
<2> similarly creates a new branch `foo`, which refers to commit `f`,
492
490
but leaves `HEAD` detached.
493
-
494
491
<3> creates a new tag `foo`, which refers to commit `f`,
495
492
leaving `HEAD` detached.
496
493
@@ -519,84 +516,89 @@ to checkout these paths out of the index.
519
516
EXAMPLES
520
517
--------
521
518
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
+
526
525
------------
527
526
$ git checkout master <1>
528
527
$ git checkout master~2 Makefile <2>
529
528
$ rm -f hello.c
530
529
$ git checkout hello.c <3>
531
530
------------
532
- +
533
531
<1> switch branch
534
532
<2> take a file out of another commit
535
533
<3> restore `hello.c` from the index
536
- +
534
+
537
535
If you want to check out _all_ C source files out of the index,
538
536
you can say
539
- +
537
+
540
538
------------
541
539
$ git checkout -- '*.c'
542
540
------------
543
- +
541
+
544
542
Note the quotes around `*.c`. The file `hello.c` will also be
545
543
checked out, even though it is no longer in the working tree,
546
544
because the file globbing is used to match entries in the index
547
545
(not in the working tree by the shell).
548
- +
546
+
549
547
If you have an unfortunate branch that is named `hello.c`, this
550
548
step would be confused as an instruction to switch to that branch.
551
549
You should instead write:
552
- +
550
+
553
551
------------
554
552
$ git checkout -- hello.c
555
553
------------
556
554
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
+
560
560
------------
561
561
$ git checkout mytopic
562
562
------------
563
- +
563
+
564
564
However, your "wrong" branch and correct `mytopic` branch may
565
565
differ in files that you have modified locally, in which case
566
566
the above checkout would fail like this:
567
- +
567
+
568
568
------------
569
569
$ git checkout mytopic
570
570
error: You have local changes to 'frotz'; not switching branches.
571
571
------------
572
- +
572
+
573
573
You can give the `-m` flag to the command, which would try a
574
574
three-way merge:
575
- +
575
+
576
576
------------
577
577
$ git checkout -m mytopic
578
578
Auto-merging frotz
579
579
------------
580
- +
580
+
581
581
After this three-way merge, the local modifications are _not_
582
582
registered in your index file, so `git diff` would show you what
583
583
changes you made since the tip of the new branch.
584
584
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
+
588
590
------------
589
591
$ git checkout -m mytopic
590
592
Auto-merging frotz
591
593
ERROR: Merge conflict in frotz
592
594
fatal: merge program failed
593
595
------------
594
- +
596
+
595
597
At this point, `git diff` shows the changes cleanly merged as in
596
598
the previous example, as well as the changes in the conflicted
597
599
files. Edit and resolve the conflict and mark it resolved with
598
600
`git add` as usual:
599
- +
601
+
600
602
------------
601
603
$ edit frotz
602
604
$ git add frotz
0 commit comments