Skip to content

Commit 8dda6c3

Browse files
felipecgitster
authored andcommitted
doc: git-checkout: reorganize examples
The examples are an ordered list, however, they are complex enough that a callout is inside example 1, and that confuses the parsers as the list continuation (`+`) is unclear (are we continuing the previous list item, or the previous callout?). We could use an open block as the asciidoctor documentation suggests, but that has a tiny formatting issue (a newline is missing). To simplify things for everyone (the reader, the writer, and the parser) let's use subsections. After this change, the HTML documentation generated with asciidoc has the right indentation. Cc: Jeff King <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8bc75a commit 8dda6c3

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

Documentation/git-checkout.txt

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,12 @@ to checkout these paths out of the index.
516516
EXAMPLES
517517
--------
518518

519-
. The following sequence checks out the `master` branch, reverts
520-
the `Makefile` to two revisions back, deletes `hello.c` by
521-
mistake, and gets it back from the index.
522-
+
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+
523525
------------
524526
$ git checkout master <1>
525527
$ git checkout master~2 Makefile <2>
@@ -529,70 +531,74 @@ $ git checkout hello.c <3>
529531
<1> switch branch
530532
<2> take a file out of another commit
531533
<3> restore `hello.c` from the index
532-
+
534+
533535
If you want to check out _all_ C source files out of the index,
534536
you can say
535-
+
537+
536538
------------
537539
$ git checkout -- '*.c'
538540
------------
539-
+
541+
540542
Note the quotes around `*.c`. The file `hello.c` will also be
541543
checked out, even though it is no longer in the working tree,
542544
because the file globbing is used to match entries in the index
543545
(not in the working tree by the shell).
544-
+
546+
545547
If you have an unfortunate branch that is named `hello.c`, this
546548
step would be confused as an instruction to switch to that branch.
547549
You should instead write:
548-
+
550+
549551
------------
550552
$ git checkout -- hello.c
551553
------------
552554

553-
. After working in the wrong branch, switching to the correct
554-
branch would be done using:
555-
+
555+
=== 2. Merge
556+
557+
After working in the wrong branch, switching to the correct
558+
branch would be done using:
559+
556560
------------
557561
$ git checkout mytopic
558562
------------
559-
+
563+
560564
However, your "wrong" branch and correct `mytopic` branch may
561565
differ in files that you have modified locally, in which case
562566
the above checkout would fail like this:
563-
+
567+
564568
------------
565569
$ git checkout mytopic
566570
error: You have local changes to 'frotz'; not switching branches.
567571
------------
568-
+
572+
569573
You can give the `-m` flag to the command, which would try a
570574
three-way merge:
571-
+
575+
572576
------------
573577
$ git checkout -m mytopic
574578
Auto-merging frotz
575579
------------
576-
+
580+
577581
After this three-way merge, the local modifications are _not_
578582
registered in your index file, so `git diff` would show you what
579583
changes you made since the tip of the new branch.
580584

581-
. When a merge conflict happens during switching branches with
582-
the `-m` option, you would see something like this:
583-
+
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+
584590
------------
585591
$ git checkout -m mytopic
586592
Auto-merging frotz
587593
ERROR: Merge conflict in frotz
588594
fatal: merge program failed
589595
------------
590-
+
596+
591597
At this point, `git diff` shows the changes cleanly merged as in
592598
the previous example, as well as the changes in the conflicted
593599
files. Edit and resolve the conflict and mark it resolved with
594600
`git add` as usual:
595-
+
601+
596602
------------
597603
$ edit frotz
598604
$ git add frotz

0 commit comments

Comments
 (0)