branch_git fetch

branch_git fetch问:Igoogledandreadmanyposts,butnonecouldmakemeunderstandthebranchdivergenceproblemyet.IfI’veremotetrackingbranch,Ioftengetintothefollowing:$gitstatus#Onbranch

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全家桶1年46,售后保障稳定

问:

I googled and read many posts, but none could make me understand the branch divergence problem yet.

If I’ve remote tracking branch, I often get into the following:

$ git status
# On branch feature/worker-interface
# Your branch and 'origin/feature/worker-interface' have diverged,
# and have 1 and 4 different commit(s) each, respectively.

Jetbrains全家桶1年46,售后保障稳定 答:

First, you can use the cherry command to see what commits differ between branches, and in what ways. So in this case, running g cherry origin/feature/worker-interface shows us the status of commits on the current branch and how they stack up against origin/feature/worker-interface. You will find 1 repo which you forgot to commit.

首先,你可以使用git cherry命令查看提交的分支的不同,也就是说你可以git cherry origin/master 查看,显示在当前分支origin/master下提交的状态,你将发现有1个版本库你忘记了提交。

Now, lets see whats happening with the ‘origin/feature/worker-interface’ and its commits.For this we can run a log command with a special format gl ..origin/feature/worker-interface --oneline

现在,让我们看看origin/master到底发生了什么情况,我们用git log ..origin/master --online 查看。

Here we see 4 commits that don’t exist in our current branch

我们发现有4个提交在我们的当前分支下不存在。

So now we have a good idea of what’s happened. you’ve made 1 commits on your local master branch, and it looks like there are 4 commits on origin/feature/worker-interface which you don’t have merged in yet. So, you could just blindly merge things together and go on your way (if they merge without conflict), but I’d like to show you how to deal with it in a more controlled manner.

所以我们很想知道这到底是什么原因导致了这种情况的发生。你在本地的master分支提交了一次,但是看上去应该是四次提交,这四次提交你都还没有进行合并过。那么,你可能盲目的把它们进行合并,但我将告诉你这应该怎么更好的处理这个问题:

1) First, create a branch that points to your current HEAD: gco -b local_changes 2) Now that we have that to keep track of those changes, we switch back to feature/worker-interface: gco feature/worker-interface 3) At this point, reset the feature/worker-interface branch to get rid of the 1 commit. 4) There you go! You can check your status of branch git status you will be prompted asnothing to commit


1),你应该创建一个分支指向你当前的HEAD ,如果有分支可以不用创建(git checkout -b local_changes)

2) 现在我们可以追踪到分支上的变化,我们切回到origin/master ,git checkout origin/master

3)之后git reset origin/master 删除origin/master 分支上的一次提交

4)OK,完工。git status查看下。

参考:http://stackoverflow.com/questions/9189413/good-and-clear-understanding-of-the-git-branches-diverged-issue

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/213416.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • mac phpstorm激活码2022【2022.01最新】2022.02.27

    (mac phpstorm激活码2022)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html2KLKA7BQFO-eyJsaWNlbnNlSW…

    2022年4月1日
    107
  • python 元类编程_Python进阶

    python 元类编程_Python进阶前言通常我们创建类都是使用class类名,但是小伙伴们有没有想过,类是由谁来创建的呢,python中常说的万物皆对象,对象是由类创建的,那类本身也可以看做是对象,类可以由元类type创建type

    2022年7月31日
    7
  • 在本地磁盘型云主机做软RAID的实践[通俗易懂]

    在本地磁盘型云主机做软RAID的实践[通俗易懂]在本地磁盘型云主机做软RAID的实践

    2022年4月21日
    51
  • 时序数据库应用_tsdb时序数据库

    时序数据库应用_tsdb时序数据库前言mysql可能大家都用的比较多且普遍,最近1年在使用PostgreSql,其大体DML语句与mysql类似,只是部分DDL语句有些区别,写一篇文章给正在应用该数据库或者准备选型该数据库的朋友,分享下使用方式与心得PostgreSqlPostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES的许多领先概念只是在比较迟的时候才…

    2022年9月27日
    3
  • python调用自己写的py文件

    python调用自己写的py文件

    2021年5月17日
    197
  • IDEA中Maven依赖下载失败解决方案[通俗易懂]

    使用IDEA进行Maven项目开发时,时不时会遇到pom.xml报错的情况,其中很大概率是因为Maven依赖的jar包下载失败,找来找去也没有找到是什么问题,困扰了很多程序猿,这里给出IDEA中Maven依赖下载失败解决方案,给大家参考,实测有用。首先检查网络有没有问题,确定网络没有问题,请看下一步多次点击重新导入Maven依赖的按钮重新导入Maven依赖有两种方式,如上图所示。如果多…

    2022年4月16日
    126

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号