git分支管理命令,idea操作git分支

    技术2025-07-09  17

    git分支管理

    idea版本回退1:本地代码回退2:强推到git 查看全部分支(本地&远程)idea操作分支切换分支创建本地分支local_branch 并切换到该分支切换到已存在的本地分支(local_branch) 删除本地分支(local_branch) 远程分支--关联-->本地分支推送本地分支local_branch到远程分支 remote_branch并建立关联关系==远程已有==remote_branch分支并且==已经关联==本地分支local_branch且本地已经切换到local_branch==远程已有==remote_branch分支但==未关联==本地分支local_branch且本地已经切换到local_branch==远程没有==remote_branch分支并且本地已经切换到local_branch 删除远程分支remote_branch

    idea版本回退

    1:本地代码回退

    此时本地已经回退到目标版本

    2:强推到git

    git push -f

    查看全部分支(本地&远程)

    说明: 1:每个本地分支只能关联一个可以pull(拉取代码)的远程分支,即该本地分支首次push(推送代码)的远程分支,目的是为了保证从远程pull(拉取)代码时保证仓库的唯一性,后续可以创建n个新的远程分支与之关联,但本地分支只能对其push(推送代码),不能pull(拉取代码) 2:关于分支合并,无法直接将“远程分支A”合并到“远程分支master”,需要先将“远程分支A”的代码拉取到本地对应的“本地分支A”,然后将本地当前分支切换到“本地分支master”并执行merge(合并)命令( git merge “本地分支A”),最后再将其push到“远程分支master”。

    git branch -a //获取远程更新 git fetch

    白色和黄色字体都代表本地分支, 黄色带星号表示当前操作的本地分支, 红色代表远程仓库分支

    idea操作分支

    切换分支

    创建本地分支local_branch 并切换到该分支

    #创建本地分支 D:\ideaProject\culture.cloud.com>git branch local_branch

    切换到已存在的本地分支(local_branch)

    执行前:当前操作分支为master 执行后:

    git checkout local_branch

    删除本地分支(local_branch)

    git branch -D local_branch

    删除后结果

    远程分支–关联–>本地分支

    目前远程仓库只有一个master主分支

    推送本地分支local_branch到远程分支 remote_branch并建立关联关系

    远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch

    //提交到本地 D:\ideaProject\culture.cloud.com>git commit -am '本地第二次提交' [master 58c4baa] '本地第二次提交' 1 file changed, 1 insertion(+), 1 deletion(-) //成功提交 //推到远程仓库 D:\ideaProject\culture.cloud.com>git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 8 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 388 bytes | 388.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [GNK-5.0] To https://gitee.com/choke/yunwen_travel.git a173338..58c4baa master -> master //成功推送 D:\ideaProject\culture.cloud.com>

    远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch

    git push -u origin/remote_branch

    远程没有remote_branch分支并且本地已经切换到local_branch

    git push origin local_branch:remote_branch

    执行命令: 执行后: 查看码云:

    删除远程分支remote_branch

    git push origin :remote_branch

    查看码云:

    Processed: 0.010, SQL: 9