git 分支的基本操作

时间:2023-03-09 09:43:23
git 分支的基本操作

git分支的基本操作。



创建私有分支:

    $git branch branchName commitID

    $git checkout -b branchName commitID

注意:git checkout -b branchName commitID = git branch branchName commitID + git checkout branchName。



合并分支(合并前需要切换到目标分支):

    $git merge sourceBranch

    $git cherry-pick commitID



查看分支:

    $git branch (-a) (-r)

    $git branch --merged 查看合并到当前分支的所有分支

    $git branch --no-merged 查看还没有合并到当前分支的所有分支



删除私有分支:

    $git branch -d/-D branchName

    -d:检查是否合并到其它分支/-D: 不检查强制删除



重命名分支:

    $git branch -m oldBranch newBranch