当前位置: 首页 > 后端技术 > Java

GIT-分支操作

时间:2023-04-02 00:28:45 Java

刷新本地分支首先查看本地分支的状态,最新的记录是新增了一个b.txt文件[root@supmangit]#gitbranch-avv*master3608563[origin/master]添加b.txt。remotes/origin/master3608563添加b.txt。然后我们在另一个分支中分支,或者直接在gitee仓库中更改仓库的内容,使用gitfetch命令刷新本地分支,看一下分支状态,会发现有新的变化[root@supmangit]#gitfetchremote:枚举对象:4,done.remote:计数对象:100%(4/4),done.remote:压缩对象:100%(2/2),done.remote:Total3(delta1),重复使用0(delta0),pack-reused0Unpackingobjects:100%(3/3),done.来自https://gitee.com/codeyuany/git3608563..cbf22f8master->origin/master[root@supmangit]#gitbranch-avv*master3608563[origin/master:behind1]addb.txt.remotes/origin/mastercbf22f8addc.txt.[root@supmangit]#使用gitmerge或gitrebase命令将远程仓库中的内容合并到本地。其实gitfetch+gitmerge除了可以合并远程分支外,和之前使用的gitpullgitmerge完全等价。也可以用于本地分支和本地分支之间的合并[root@supmangit]#gitmergeorigin/masterupdate3608563..cbf22f8快进c.txt|1+1文件更改,1插入(+)创建模式100644c.txt[root@supmangit]#gitbranch-avv*mastercbf22f8[origin/master]addc.txt.remotes/origin/mastercbf22f8addc.TXT。要创建分支,可以使用gitbranch命令查看当前分支。[root@supmangit]#gitbranch*master然后我们用gitbranch+分支名新建一个分支,查看有哪些分支。[root@supmangit]#gitbranchdev[root@supmangit]#gitbranch-adev*masterremotes/origin/master使用gitcheckout+分支名切换分支,查看分支带*代表当前分支[root@supmangit]#gitcheckoutdevswitchtobranch'dev'[root@supmangit]#gitbranch*devmasterusegitpush+hostname+localbranchname:远程分支名将本地分支推送到远程服务器[root@supmangit]#gitpushorigindev:devUsernamefor'https://gitee.com':codeyuanyPasswordfor'https://codeyuany@gitee.com':Total0(delta0),reused0(delta0)remote:由GITEE.COM提供支持[GNK-6.1]remote:通过访问在Gitee上创建“dev”的拉取请求:remote:https://gitee.com/codeyuany/git/pull/new/codeyuany:dev...码元y:masterTohttps://gitee.com/codeyuany/git.git*[newbranch]dev->dev[root@supmangit]#gitbranch-a*devmasterremotes/origin/devremotes/origin/masterput的远程分支更新到本地[root@supmangit]#gitpullorigindevfromhttps://gitee.com/codeyuany/git*branchdev->FETCH_HEADupdatecbf22f8..107c861Fast-forwardc.txt|2+-1filechanged,1insertion(+),1deletion(-)允许本地分支跟踪远程分支,也就是将本地分支和远程分支关联起来[root@supmangit]#gitbranch-uorigin/devdev分支dev被设置为跟踪来自origin的远程分支dev。[root@supmangit]#gitpull已经是最新的。删除分支gitpushhostname--deletebranchnamedeleteremotebranch,gitbranch-ddevdeletelocalbranch[root@supmangit]#gitpushorigin--deletedevUsernamefor'https://gitee.com':codeyuanyPasswordfor'https://codeyuany@gitee.com':remote:PoweredbyGITEE.COM[GNK-6.1]Tohttps://gitee.com/codeyuany/git.git-[deleted]dev[root@supmangit]#gitbranch-a*devmasterremotes/origin/master[root@supmangit]#gitbranch-ddeverror:无法删除你当前所在的分支'开发'。