(master)$git checkout branchname file1 file2 files3 git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>... When <paths> or --patch are given, git checkout does not switch branches. It updates the named paths in the working tree from the index file or from a named <tree-ish> (most often a commit). The <tree-ish> argument can be used to specify a specific tree-ish (i.e. commit, tag or tree) to update the index for the given paths before updating the working tree.
$ git checkout master (1) $ git checkout master~2 Makefile (2) $ rm -f hello.c $ git checkout hello.c (3)
$ git checkout -- '*.c'Note the quotes around
*.c
.
The removed file hello.c
will also be checked out, even though it is
no longer in the working tree, because the file globbing is used to match entries in the
index (not in the working tree by the shell).
hello.c
, this step:
$ git checkout hello.cwould be confused as an instruction to switch to that branch.
You should instead write:
$ git checkout -- hello.c
Casiano Rodriguez León 2015-01-07