Skip to content

Commit 57a3b97

Browse files
committed
Merge branch 'fc/doc-checkout-markup-updates'
Doc mark-up update. * fc/doc-checkout-markup-updates: doc: git-checkout: reorganize examples doc: git-checkout: trivial callout cleanup
2 parents d6661e6 + 8dda6c3 commit 57a3b97

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

Documentation/git-checkout.txt

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
519516
EXAMPLES
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+
537535
If you want to check out _all_ C source files out of the index,
538536
you can say
539-
+
537+
540538
------------
541539
$ git checkout -- '*.c'
542540
------------
543-
+
541+
544542
Note the quotes around `*.c`. The file `hello.c` will also be
545543
checked out, even though it is no longer in the working tree,
546544
because the file globbing is used to match entries in the index
547545
(not in the working tree by the shell).
548-
+
546+
549547
If you have an unfortunate branch that is named `hello.c`, this
550548
step would be confused as an instruction to switch to that branch.
551549
You 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+
564564
However, your "wrong" branch and correct `mytopic` branch may
565565
differ in files that you have modified locally, in which case
566566
the above checkout would fail like this:
567-
+
567+
568568
------------
569569
$ git checkout mytopic
570570
error: You have local changes to 'frotz'; not switching branches.
571571
------------
572-
+
572+
573573
You can give the `-m` flag to the command, which would try a
574574
three-way merge:
575-
+
575+
576576
------------
577577
$ git checkout -m mytopic
578578
Auto-merging frotz
579579
------------
580-
+
580+
581581
After this three-way merge, the local modifications are _not_
582582
registered in your index file, so `git diff` would show you what
583583
changes 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
590592
Auto-merging frotz
591593
ERROR: Merge conflict in frotz
592594
fatal: merge program failed
593595
------------
594-
+
596+
595597
At this point, `git diff` shows the changes cleanly merged as in
596598
the previous example, as well as the changes in the conflicted
597599
files. 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

Comments
 (0)