需要Git rebase arguments上下文解释 [英] Git rebase arguments context explanation needed

查看:162
本文介绍了需要Git rebase arguments上下文解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些分支的上下文中经常使用 git rebase 。例如,如果我想在 master 分支之上移动特性分支的基础(基于最新的提交) - 教程说:

  git checkout feature 
git rebase master

这样的教程之后,有很多问题。例如:如何在不检出的情况下执行相同的操作。我如何用 - 在选项上执行相同的操作。 - 到之间有什么区别,只是rebase。我可以通过一系列提交还是必须是整个分支?等等。

我已经多次阅读手册页,但仍然有很大的差距。

主要问题是: git如何解析不同场景下的参数,我应该如何解释/想象他们在我的脑海中?例如:

  git rebase master 
git rebase feature master
git rebase --onto master feature
git rebase HEAD〜4 HEAD〜2
git rebase --onto HEAD〜4 HEAD〜2

让我们假设我们有以下的回购:

$ $ $ $ $ $ $ $ $ $ Z $ W $ HEAD,test-branch *

A - B - C - D - E(主)
\
1 - 2 - 3(功能)

测试分支被检出。


解决方案

完整的rebase命令就是这样。

  git rebase --onto< to> <上游> <分支到变基> 

Git将执行分支到分支的所有更改不在上游中,并将它们放在上面



默认值为...




  • 分支转化为:当前分支

  • 上游:分支到分叉的跟踪分支

  • :upstream



git checkout feature; git rebase master 确实是 git rebase --onto master master feature



您一般希望上游是一样的,但有时对于精细手术来说它们有所不同。
$ b $在上游之间的区别已经清楚了。

  A  -  B  -  C  -  D master 
\
E - F - G next
\
H - I - J topic

如果 git rebase master主题,它会重新发布 topic 与 master 没有共同之处的所有提交。 。所有介入分支头将被忽略。那就是E,F,G,H,I和J.因为默认为上游,它会把那些在 master 上。

  A  -  B  -  C  -  D master 
\\ \\ \\ \\
\ E'-F'-G'-H'-I'-J'主题
\
E - F - G next

如果您只想将来自下一个的提交改为主题?这是 - 到变得有用的地方。告诉Git上游是 next ,但是你想要变成 master 。因此运行 git rebase - 去掌握下一个主题。这只会选择H,I和J。

  A  -  B  -  C  -  D master 
\\ \\\
\ H'-I'-J'topic
\
E - F - G next


Very often git rebase used in a context of some branch. For example, if I want to move the base of feature branch on top of the master branch (based on latest commits) - tutorials say:

git checkout feature
git rebase master 

After tutorials like that, there are a lot of questions. Eg: how to perform the same action without checking out. How can I do the same action with --onto option. What the difference between --onto and just rebase. Can I pass a range of commits or it must be a whole branch? Etc..

I've read man page several times but still have a big gap.

So the main problem is: how git parse the args in different scenarios and how should I interpret/imagine them in my head? For example:

git rebase master
git rebase feature master
git rebase --onto master feature
git rebase HEAD~4 HEAD~2
git rebase --onto HEAD~4 HEAD~2

Let's assume we have the following repo:

Z -- W (HEAD, test-branch*) 

A -- B -- C -- D -- E (master)
     \
      1 -- 2 -- 3 (feature)

test-branch is checked out.

解决方案

The full rebase command is this.

git rebase --onto <onto> <upstream> <branch-to-rebase>

Git will take all the changes in branch-to-rebase which are not in upstream and put them on top of onto.

The defaults are...

  • branch-to-rebase: current branch
  • upstream: branch-to-rebase's tracking branch
  • onto: upstream

git checkout feature; git rebase master is really git rebase --onto master master feature.

You generally want onto and upstream to be the same, but sometimes it's useful for them to be different for delicate surgery. The difference between upstream and onto is made clear in this example.

           A--B--C--D master
               \
                E--F--G next
                       \
                        H--I--J topic

If you git rebase master topic, it will rebase all the commits that topic does not have in common with master. All intervening branch heads will be ignored. That is E, F, G, H, I and J. Since onto defaults to upstream, it will put those on master. You'll wind up with this.

           A--B--C--D master
               \     \
                \     E'-F'-G'-H'-I'-J' topic
                 \
                  E--F--G next

What if you just want the commits from next to topic? This is where --onto becomes useful. Tell Git that the upstream is next, but you want to rebase onto master. So run git rebase --onto master next topic. This will select just H, I and J.

           A--B--C--D master
               \     \
                \     H'-I'-J' topic
                 \
                  E--F--G next

这篇关于需要Git rebase arguments上下文解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆