git checkout
Basic commands
Create a branch based on the current branch
git checkout -b "new-branch-name"Create a branch based on the hash value or relative to the latest commit of the current branch
git checkout -b "new-branch-name" <sha1-of-commit or HEAD~3>How to reset or revert a file to a specific revision?
git checkout c5f567 -- file1/to/restore file2/to/restoreHard reset of a single file
git checkout -- file-name-that-you-deleted-- basically means: treat every argument after
--
as a file name. More details, please refer to this link.
Checking out a PR branch for coding review
Add a contributor's remote:
$ git remote add [REFERENCE_NAME] [email protected]:[CONTRIBUTOR_USERNAME]/[REPOSITORY].github.io.gitREFERENCE_NAME is usually a contributor's name, e.g. aaron, mild.
Then, fetch all branches of a contributor's remote.
$ git fetch [REFERENCE_NAME]Git will suggest a local branch and a tracking remote branch that you can checkout later without
-b
option which you can't do in other cases"* [new branch] branch-name -> [REFERENCE_NAME]/branch-nameYou can now checkout a new branch with:
$ git checkout branch-nameThis keeps a local branch on your computer.
You can also checkout a temporary branch with:
$ git checkout [REFERENCE_NAME]/branch-name
Loading comments...