75
`git checkout <tree-ish> [--] <pathspec>...`::
76
`git checkout <tree-ish> --pathspec-from-file=<file> [--pathspec-file-nul]`::
77
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`.
84
85
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [--] <pathspec>...`::
86
`git checkout [-f|--ours|--theirs|-m|--conflict=<style>] --pathspec-from-file=<file> [--pathspec-file-nul]`::
87
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`.
94
+
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.
101
102
`git checkout (-p|--patch) [<tree-ish>] [--] [<pathspec>...]`::
103
This is similar to the previous two modes, but lets you use the