“git rebase -i master”与“git rebase -i origin / master”之间的区别 [英] Difference between `git rebase -i master` vs `git rebase -i origin/master`

查看:2216
本文介绍了“git rebase -i master”与“git rebase -i origin / master”之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在推送Git之前合并多个提交



基于我的理解,如果我使用 git rebase -i master ,那么稍后我仍然需要 git push origin master 上传更改。



问题> rebase -i master code> vs rebase -i origin / master



谢谢 $ b $ git rev-parse master



 git rev-parse origin / master 

您会看到两个SHA-1。如果这两个SHA-1值相同,则两个rebase命令将完成相同的操作。如果不是,他们会做不同的事情。



< upstream> 使用参数



< upstream> 参数 git rebase 有两个目的:


  • 它选择哪些提交获得重定位,并且

  • 如果没有< to>< / code>参数,它会选择樱桃选择序列的起点。


(请记住,这里的语法是 git rebase [options] [< upstream> [< branch>]< / code>所以<$ c $在你的例子中,c> master origin / master 提供了一个< upstream> 。你必须使用 - 到选项来提供<到> ,而你没有这样做,所以< upstream> 代替它。)



要查看选择了哪些提交,可以使用 git rev-list (或者更详细的等价物, git log )。选择用于重新绑定的实际提交是 包含在当前分支中但不包含在<上游> 。即:

  git rev-list master..HEAD 

或$:

  git rev-list origin / master..HEAD 

。 (用 log 替换 rev-list )以详细查看它们,或者 log --oneline



什么是rebase



rebase 命令通过复制提交,然后将分支名称设置为指向新的最尖端副本。



如果您使用交互式版本,它会将提交ID和说明放入可以编辑的文件中。否则,它会按顺序遍历所有的提交ID。



以前的 git rev-list 命令在< to> < code>>的基础上,启动挑选顺序, rebase / code>提交。也就是说,< to> commit是副本的起点。

然后,对于每个提交ID, rebase 本质上运行 git cherry-pick (如果您使用的是交互式版本,则没有基本上它实际上使用 git cherry-pick ,并根据您的指令编辑进行一些修改)。这将原始提交复制到新分支提示中的新提交。当每个提交被复制时,新的分支会增长以包含全部。



最后,一旦所有提交都被复制, git rebase 更改最初的当前分支名称,以便它指向新分支上的新提示最多的提交。



请注意,在此过程中无处执行git请注意<上游> 中是否出现 origin 这个词。它只是将< upstream> 参数解析为它的SHA-1,然后运行它。


Combining multiple commits before pushing in Git

Based on my understanding, if I use git rebase -i master, then later I still need to git push origin master to upload the changes.

Question> What is the difference between rebase -i master vs rebase -i origin/master?

Thank you

解决方案

Before we go any further, run:

git rev-parse master

and:

git rev-parse origin/master

You'll see two SHA-1s. If those two SHA-1 values are the same, the two rebase commands will do the same thing. If not, they will do different things.

How the <upstream> argument is used

The <upstream> argument to git rebase has two purposes:

  • it selects which commits get rebased, and
  • in the absence of an <onto> argument, it selects the starting point for the sequence of cherry-picks.

(Remember, the syntax here is git rebase [options] [<upstream> [<branch>]] so master and origin/master in your examples provide an <upstream>. You must use the --onto option to provide an <onto>, and you're not doing so, so the <upstream> provides it instead.)

To see which commits are selected, you can use git rev-list (or its more-verbose equivalent, git log). The actual commits selected for rebasing are those that are contained in the current branch but are not contained in the <upstream>. That is:

git rev-list master..HEAD

or:

git rev-list origin/master..HEAD

respectively. (Replace rev-list with log to see them in detail, or log --oneline to see them as one-line descriptions.)

What rebase does

The rebase command works by copying commits, then setting the branch name to point to the new, tip-most copy.

If you use the interactive version, it puts the commit IDs and instructions into a file that you can edit. Otherwise it just goes through all the commit IDs from the above git rev-list commands, in order.

Before starting the sequence of cherry-picks, rebase detaches HEAD at the <onto> commit. That is, the <onto> commit is the starting point for the copies.

Then, for each commit ID, rebase essentially runs git cherry-pick (if you're using the interactive version there's no "essentially" about it, it actually uses git cherry-pick, with some modifications based on your instruction editing). This copies the original commit to a new one at the new branch-tip. As each commit is copied, the new branch grows to contain them all.

Finally, once all the commits are copied, git rebase changes the originally-current branch name so that it points to the new tip-most commit on the new branch.

Note that nowhere in this process does git care whether the word origin appears in <upstream>. It simply resolves the <upstream> argument to its SHA-1 and then runs with that.

这篇关于“git rebase -i master”与“git rebase -i origin / master”之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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