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 基本操作Git 基本操作


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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章