git checkout
时间: 2023-10-26 18:42:58 浏览: 93
The `git checkout` command is used to switch between different branches or to restore files to a previous version. It has several different use cases:
1. Switching branches: `git checkout <branch-name>`
This command switches to the specified branch and updates the working directory to reflect the contents of that branch.
2. Creating a new branch: `git checkout -b <new-branch-name>`
This command creates a new branch with the given name and switches to it.
3. Restoring a file to a previous version: `git checkout <commit-hash> <file>`
This command restores the specified file to the version that was committed at the specified commit-hash.
4. Discarding local changes: `git checkout -- <file>`
This command discards any local changes made to the specified file and restores it to the state it was in at the last commit.
Overall, `git checkout` is a powerful command that allows you to switch between different branches or restore files to previous versions.
阅读全文