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
This commit is contained in:
commit
57a3b971e9
@ -483,14 +483,11 @@ $ git checkout -b foo # or "git switch -c foo" <1>
|
|||||||
$ git branch foo <2>
|
$ git branch foo <2>
|
||||||
$ git tag foo <3>
|
$ git tag foo <3>
|
||||||
------------
|
------------
|
||||||
|
|
||||||
<1> creates a new branch `foo`, which refers to commit `f`, and then
|
<1> creates a new branch `foo`, which refers to commit `f`, and then
|
||||||
updates `HEAD` to refer to branch `foo`. In other words, we'll no longer
|
updates `HEAD` to refer to branch `foo`. In other words, we'll no longer
|
||||||
be in detached `HEAD` state after this command.
|
be in detached `HEAD` state after this command.
|
||||||
|
|
||||||
<2> similarly creates a new branch `foo`, which refers to commit `f`,
|
<2> similarly creates a new branch `foo`, which refers to commit `f`,
|
||||||
but leaves `HEAD` detached.
|
but leaves `HEAD` detached.
|
||||||
|
|
||||||
<3> creates a new tag `foo`, which refers to commit `f`,
|
<3> creates a new tag `foo`, which refers to commit `f`,
|
||||||
leaving `HEAD` detached.
|
leaving `HEAD` detached.
|
||||||
|
|
||||||
@ -519,84 +516,89 @@ to checkout these paths out of the index.
|
|||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
||||||
. The following sequence checks out the `master` branch, reverts
|
=== 1. Paths
|
||||||
the `Makefile` to two revisions back, deletes `hello.c` by
|
|
||||||
mistake, and gets it back from the index.
|
The following sequence checks out the `master` branch, reverts
|
||||||
+
|
the `Makefile` to two revisions back, deletes `hello.c` by
|
||||||
|
mistake, and gets it back from the index.
|
||||||
|
|
||||||
------------
|
------------
|
||||||
$ git checkout master <1>
|
$ git checkout master <1>
|
||||||
$ git checkout master~2 Makefile <2>
|
$ git checkout master~2 Makefile <2>
|
||||||
$ rm -f hello.c
|
$ rm -f hello.c
|
||||||
$ git checkout hello.c <3>
|
$ git checkout hello.c <3>
|
||||||
------------
|
------------
|
||||||
+
|
|
||||||
<1> switch branch
|
<1> switch branch
|
||||||
<2> take a file out of another commit
|
<2> take a file out of another commit
|
||||||
<3> restore `hello.c` from the index
|
<3> restore `hello.c` from the index
|
||||||
+
|
|
||||||
If you want to check out _all_ C source files out of the index,
|
If you want to check out _all_ C source files out of the index,
|
||||||
you can say
|
you can say
|
||||||
+
|
|
||||||
------------
|
------------
|
||||||
$ git checkout -- '*.c'
|
$ git checkout -- '*.c'
|
||||||
------------
|
------------
|
||||||
+
|
|
||||||
Note the quotes around `*.c`. The file `hello.c` will also be
|
Note the quotes around `*.c`. The file `hello.c` will also be
|
||||||
checked out, even though it is no longer in the working tree,
|
checked out, even though it is no longer in the working tree,
|
||||||
because the file globbing is used to match entries in the index
|
because the file globbing is used to match entries in the index
|
||||||
(not in the working tree by the shell).
|
(not in the working tree by the shell).
|
||||||
+
|
|
||||||
If you have an unfortunate branch that is named `hello.c`, this
|
If you have an unfortunate branch that is named `hello.c`, this
|
||||||
step would be confused as an instruction to switch to that branch.
|
step would be confused as an instruction to switch to that branch.
|
||||||
You should instead write:
|
You should instead write:
|
||||||
+
|
|
||||||
------------
|
------------
|
||||||
$ git checkout -- hello.c
|
$ git checkout -- hello.c
|
||||||
------------
|
------------
|
||||||
|
|
||||||
. After working in the wrong branch, switching to the correct
|
=== 2. Merge
|
||||||
branch would be done using:
|
|
||||||
+
|
After working in the wrong branch, switching to the correct
|
||||||
|
branch would be done using:
|
||||||
|
|
||||||
------------
|
------------
|
||||||
$ git checkout mytopic
|
$ git checkout mytopic
|
||||||
------------
|
------------
|
||||||
+
|
|
||||||
However, your "wrong" branch and correct `mytopic` branch may
|
However, your "wrong" branch and correct `mytopic` branch may
|
||||||
differ in files that you have modified locally, in which case
|
differ in files that you have modified locally, in which case
|
||||||
the above checkout would fail like this:
|
the above checkout would fail like this:
|
||||||
+
|
|
||||||
------------
|
------------
|
||||||
$ git checkout mytopic
|
$ git checkout mytopic
|
||||||
error: You have local changes to 'frotz'; not switching branches.
|
error: You have local changes to 'frotz'; not switching branches.
|
||||||
------------
|
------------
|
||||||
+
|
|
||||||
You can give the `-m` flag to the command, which would try a
|
You can give the `-m` flag to the command, which would try a
|
||||||
three-way merge:
|
three-way merge:
|
||||||
+
|
|
||||||
------------
|
------------
|
||||||
$ git checkout -m mytopic
|
$ git checkout -m mytopic
|
||||||
Auto-merging frotz
|
Auto-merging frotz
|
||||||
------------
|
------------
|
||||||
+
|
|
||||||
After this three-way merge, the local modifications are _not_
|
After this three-way merge, the local modifications are _not_
|
||||||
registered in your index file, so `git diff` would show you what
|
registered in your index file, so `git diff` would show you what
|
||||||
changes you made since the tip of the new branch.
|
changes you made since the tip of the new branch.
|
||||||
|
|
||||||
. When a merge conflict happens during switching branches with
|
=== 3. Merge conflict
|
||||||
the `-m` option, you would see something like this:
|
|
||||||
+
|
When a merge conflict happens during switching branches with
|
||||||
|
the `-m` option, you would see something like this:
|
||||||
|
|
||||||
------------
|
------------
|
||||||
$ git checkout -m mytopic
|
$ git checkout -m mytopic
|
||||||
Auto-merging frotz
|
Auto-merging frotz
|
||||||
ERROR: Merge conflict in frotz
|
ERROR: Merge conflict in frotz
|
||||||
fatal: merge program failed
|
fatal: merge program failed
|
||||||
------------
|
------------
|
||||||
+
|
|
||||||
At this point, `git diff` shows the changes cleanly merged as in
|
At this point, `git diff` shows the changes cleanly merged as in
|
||||||
the previous example, as well as the changes in the conflicted
|
the previous example, as well as the changes in the conflicted
|
||||||
files. Edit and resolve the conflict and mark it resolved with
|
files. Edit and resolve the conflict and mark it resolved with
|
||||||
`git add` as usual:
|
`git add` as usual:
|
||||||
+
|
|
||||||
------------
|
------------
|
||||||
$ edit frotz
|
$ edit frotz
|
||||||
$ git add frotz
|
$ git add frotz
|
||||||
|
Loading…
Reference in New Issue
Block a user