Skip to content

Commit 9e9f490

Browse files
committed
doc: git-checkout: clarify restoring files section
- Reword to avoid jargon ("tree-ish", "index") where possible. Use "commit or tree" and "stage" (as a verb) instead where appropriate - Add examples - Use a simpler sentence structure to describe options for handling unmerged entries: "use -f to.., use --ours to..., or use -m to.." Signed-off-by: Julia Evans <[email protected]>
1 parent 9f6b6ff commit 9e9f490

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Documentation/git-checkout.adoc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,24 @@ Omitting _<branch>_ detaches `HEAD` at the tip of the current branch.
7474
`git checkout <tree-ish> [--] <pathspec>...`::
7575
`git checkout <tree-ish> --pathspec-from-file=<file> [--pathspec-file-nul]`::
7676
77-
Overwrite both the index and the working tree with the
78-
contents at the _<tree-ish>_ for the files that match the pathspec.
77+
Replace the specified files and/or directories with the version from
78+
the given commit or tree and stage the files' contents.
79+
+
80+
For example, `git checkout main file.txt` will replace `file.txt`
81+
with the version from `main`.
7982
8083
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [--] <pathspec>...`::
8184
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] --pathspec-from-file=<file> [--pathspec-file-nul]`::
8285
83-
Overwrite working tree with the contents in the index for the files
84-
that match the pathspec.
86+
Discard any unstaged changes to the specified files and/or directories.
87+
This works by copying the file from the index to your working directory.
8588
+
86-
The index may contain unmerged entries because of a previous failed merge.
87-
By default, if you try to check out such an entry from the index, the
88-
checkout operation will fail and nothing will be checked out.
89-
Using `-f` will ignore these unmerged entries. The contents from a
90-
specific side of the merge can be checked out of the index by
91-
using `--ours` or `--theirs`. With `-m`, changes made to the working tree
92-
file can be discarded to re-create the original conflicted merge result.
93-
89+
This will fail if the file has a merge conflict and you haven't yet run
90+
`git add file.txt` (or something equivalent) to mark it as resolved.
91+
You can use `-f` to ignore the unmerged files instead of failing, use
92+
`--ours` or `--theirs` to replace them with the version from a specific
93+
side of the merge, or use `-m` to replace them with the original
94+
conflicted merge result.
9495
`git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>...]`::
9596
This is similar to the previous two modes, but lets you use the
9697
interactive interface to show the "diff" output and choose which

0 commit comments

Comments
 (0)