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