git checkout v1.2.3 -- file # tag v1.2.3git checkout stable -- file # stable branchgit checkout origin/master -- file # upstream mastergit checkout HEAD -- file # the version from the most recent commitgit checkout HEAD^ -- file # the version before the most recent commit
$ git statusOn branch masterChanges not staged for commit:(use "git add <file>..." to update what will be committed)(use "git checkout -- <file>..." to discard changes in working directory)
modified: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
如果从这一点开始,我们做git checkout,结果是这样的:
$ git checkout HEAD -- b.txt$ git statusOn branch masternothing to commit, working directory clean
如果我们做git reset,结果是:
$ git reset HEAD -- b.txtUnstaged changes after reset:M b.txt$ git statusOn branch masterChanges not staged for commit:(use "git add <file>..." to update what will be committed)(use "git checkout -- <file>..." to discard changes in working directory)
modified: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git statusOn branch masterChanges to be committed:(use "git reset HEAD <file>..." to unstage)
modified: b.txt
如果从这一点开始,我们做git checkout,结果是这样的:
$ git checkout HEAD -- b.txt$ git statusOn branch masternothing to commit, working directory clean
如果我们做git reset,结果是:
$ git reset HEAD -- b.txtUnstaged changes after reset:M b.txt$ git statusOn branch masterChanges not staged for commit:(use "git add <file>..." to update what will be committed)(use "git checkout -- <file>..." to discard changes in working directory)
modified: b.txt
no changes added to commit (use "git add" and/or "git commit -a")