git checkout 命令
git branch
git branch -a
pm@pm:~/repo/common$ git checkout --remotes/origin/android15-6.6 error: unknown option `remotes/origin/android15-6.6' usage: git checkout [<options>] <branch> or: git checkout [<options>] [<branch>] -- <file>... -b <branch> create and checkout a new branch -B <branch> create/reset and checkout a branch -l create reflog for new branch --guess second guess 'git checkout <no-such-branch>' (default) --overlay use overlay mode (default) -q, --quiet suppress progress reporting --recurse-submodules[=<checkout>] control recursive updating of submodules --progress force progress reporting -m, --merge perform a 3-way merge with the new branch --conflict <style> conflict style (merge or diff3) -d, --detach detach HEAD at named commit -t, --track set upstream info for new branch -f, --force force checkout (throw away local modifications) --orphan <new-branch> new unparented branch --overwrite-ignore update ignored files (default) --ignore-other-worktrees do not check if another worktree is holding the given ref -2, --ours checkout our version for unmerged files -3, --theirs checkout their version for unmerged files -p, --patch select hunks interactively --ignore-skip-worktree-bits do not limit pathspecs to sparse entries only --pathspec-from-file <file> read pathspec from file --pathspec-file-nul with --pathspec-from-file, pathspec elements are separated with NUL character
git checkout 命令
git checkout 命令用于在不同的分支之间切换、恢复文件、创建新分支等操作。
注意:git checkout 命令在 Git 2.23 版本后引入了 git switch 和 git restore 命令,分别用于分支切换和文件恢复,以提供更清晰的语义和错误检查。如果你使用较新的 Git 版本,可以考虑使用这些命令代替 git checkout。
切换分支:
以下命令允许你从当前分支切换到指定的分支 <branch-name>:
git checkout <branch-name>
例如将你的工作目录切换到主分支:
git checkout master
创建新分支并切换:
以下命令用于创建一个新分支 <new-branch-name> 并立即切换到新创建的分支:
git checkout -b <new-branch-name>
例如创建一个名为 feature-branch 的新分支并切换到它:
git checkout -b feature-branch
切换到前一个分支:
以下命令可以让你快速切换回前一个分支,无需记住分支名称:
git checkout -
检出文件:
以下命令可以将指定文件 <file> 恢复到最新的提交状态,丢弃所有未提交的更改,这对于撤销不需要的更改非常有用:
git checkout -- <file>
切换到特定提交:
你可以使用提交的哈希值 <commit-hash> 来切换到特定的提交状态。这将使你进入"分离头指针"状态,只能查看历史记录,而不能进行分支操作。通常情况下,不建议在分离头指针状态下工作,因为更改可能会丢失。
git checkout <commit-hash>
切换到标签:
如果你有一个标签 <tag-name>,你可以使用这个命令来切换到该标签所指向的提交状态。
git checkout tags/<tag-name>
https://www.runoob.com/git/git-checkout.html
标签:
git
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2022-03-16 AAAAA Ubuntu add a project to GitHub Repository
2022-03-16 How to Use RSA Key for SSH Authentication Automatically log-in to Linux systems even without a password.
2022-03-16 Ubuntu16.4上传本地项目到gitHub仓库 AAAA
2021-03-16 android开发——阿里巴巴fastJson的使用(json转为对象)及JSON三种开源解析文档AAAAA
2019-03-16 文件上传与下载(一)简单实现
2019-03-16 文件上传与下载(三)fileupload 实现
2019-03-16 JAVA文件上传-使用Apache----fileupload