`git rebase` not updating branch?

三世轮回 提交于 2019-12-11 05:07:30

问题


I have this:

        master
        |   foo
        |   |
        v   v             bar
A---B---C---D             |
             \            v
              \---E---F---G

I want this:

        master
        |   foo
        |   |
        v   v         bar
A---B---C---D         |
         \            v
          \---E---F---G

so I think I need to do:

git checkout bar
git rebase master

but Git thinks otherwise:

Current branch bar is up-to-date.

and leaves everything as it is.

What do I need to run to make Git do what I want?


回答1:


The version of git rebase that you are doing, takes all of the commits on the branch bar which are not already on master and writes them onto master. This is commits D through F, which isn't what you want because it doesn't skip commit D. One solution is to use the --onto flag:

git checkout bar
git rebase --onto master foo

This version of rebase will take all of the commits on the branch bar but not on branch foo and rewrite them onto master. This will result in exactly the history for bar that you want.




回答2:


Commit D is included on the branch bar. One option is to do an interactive rebase and delete commit D from branch bar.

  1. git checkout bar
  2. git rebase -i master
  3. In text editor delete line of commit D
  4. Save and close

As long as you have a tag or branch on commit D (or that includes commit D) (for example foo) you should not lose it. Also remember that if the commits after D depend on changes in D you will get conflicts.



来源:https://stackoverflow.com/questions/52192249/git-rebase-not-updating-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!