Skip to content

Commit 413cee3

Browse files
committed
doc: git-checkout: clarify restoring files section
From user feedback on this section: 3 users don't know what "tree-ish" means and 3 users don't know what "pathspec" means. One user also says that the section is very confusing and that they don't understand what the "index" is. From conversations on Mastodon, several users said that their impression is that "the index" means the same thing as "HEAD". It would be good to give those users (and other users who do not know what "index" means) a hint as to its meaning. Make this section more accessible to users who don't know what the terms "pathspec", "tree-ish", and "index" mean by using more familiar language and adding examples. Signed-off-by: Julia Evans <[email protected]>
1 parent 5248665 commit 413cee3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Documentation/git-checkout.adoc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,29 @@ Omitting _<branch>_ detaches `HEAD` at the tip of the current branch.
7575
`git checkout <tree-ish> [--] <pathspec>...`::
7676
`git checkout <tree-ish> --pathspec-from-file=<file> [--pathspec-file-nul]`::
7777
78-
Overwrite both the index and the working tree with the
79-
contents at the _<tree-ish>_ for the files that match the pathspec.
78+
Replace the specified files and/or directories with the version from
79+
the given commit or tree and add them to the index
80+
(also known as "staging area").
81+
+
82+
For example, `git checkout main file.txt` will replace `file.txt`
83+
with the version from `main`.
8084
8185
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [--] <pathspec>...`::
8286
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] --pathspec-from-file=<file> [--pathspec-file-nul]`::
8387
84-
Overwrite working tree with the contents in the index for the files
85-
that match the pathspec.
88+
Replace the specified files and/or directories with the version from
89+
the index.
90+
+
91+
For example, if you check out a commit, edit `file.txt`, and then
92+
decide those changes were a mistake, `git checkout file.txt` will
93+
discard any unstaged changes to `file.txt`.
8694
+
87-
The index may contain unmerged entries because of a previous failed merge.
88-
By default, if you try to check out such an entry from the index, the
89-
checkout operation will fail and nothing will be checked out.
90-
Using `-f` will ignore these unmerged entries. The contents from a
91-
specific side of the merge can be checked out of the index by
92-
using `--ours` or `--theirs`. With `-m`, changes made to the working tree
93-
file can be discarded to re-create the original conflicted merge result.
95+
This will fail if the file has a merge conflict and you haven't yet run
96+
`git add file.txt` (or something equivalent) to mark it as resolved.
97+
You can use `-f` to ignore the unmerged files instead of failing, use
98+
`--ours` or `--theirs` to replace them with the version from a specific
99+
side of the merge, or use `-m` to replace them with the original
100+
conflicted merge result.
94101
95102
`git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>...]`::
96103
This is similar to the previous two modes, but lets you use the

0 commit comments

Comments
 (0)