git rebase vs git rebase <upstream>

时间:2016-07-14 18:57:40

标签: git

要重现我所处的情况,您可以执行以下操作。

git rebase parent child-1

现在,如果我运行git checkout child-1 && git rebase,您将收到合并冲突,但如果您$:~/webroot/test-repo$ GIT_TRACE=1 git rebase parent child-1 trace: exec: 'git-rebase' 'parent' 'child-1' trace: run_command: 'git-rebase' 'parent' 'child-1' trace: built-in: git 'rev-parse' '--parseopt' '--' 'parent' 'child-1' trace: built-in: git 'rev-parse' '--git-dir' trace: built-in: git 'rev-parse' '--is-bare-repository' trace: built-in: git 'rev-parse' '--show-toplevel' trace: built-in: git 'config' '--bool' 'rebase.stat' trace: built-in: git 'config' '--bool' 'rebase.autostash' trace: built-in: git 'config' '--bool' 'rebase.autosquash' trace: built-in: git 'rev-parse' '--verify' 'parent^0' trace: built-in: git 'rev-parse' '--verify' 'parent^0' trace: built-in: git 'show-ref' '--verify' '--quiet' '--' 'refs/heads/child-1' trace: built-in: git 'rev-parse' '-q' '--verify' 'refs/heads/child-1' trace: built-in: git 'rev-parse' '--verify' 'HEAD' trace: built-in: git 'update-index' '-q' '--ignore-submodules' '--refresh' trace: built-in: git 'diff-files' '--quiet' '--ignore-submodules' trace: built-in: git 'diff-index' '--cached' '--quiet' '--ignore-submodules' 'HEAD' '--' trace: built-in: git 'merge-base' 'd29fb1b0ab2eefba0f8ef13fd4e37d61acb9ee6f' '75d8979d743ba575de680fd04d517aa74e813819' First, rewinding head to replay your work on top of it... trace: built-in: git 'checkout' '-q' 'd29fb1b0ab2eefba0f8ef13fd4e37d61acb9ee6f^0' trace: built-in: git 'update-ref' 'ORIG_HEAD' '75d8979d743ba575de680fd04d517aa74e813819' trace: built-in: git 'format-patch' '-k' '--stdout' '--full-index' '--ignore-if-in-upstream' '--src-prefix=a/' '--dst-prefix=b/' '--no-renames' '--no-cover-letter' 'd29fb1b0ab2eefba0f8ef13fd4e37d61acb9ee6f..75d8979d743ba575de680fd04d517aa$ 4e813819' trace: exec: 'git-am' '--rebasing' '--resolvemsg= When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort". ' trace: run_command: 'git-am' '--rebasing' '--resolvemsg= When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort". ' trace: built-in: git 'rev-parse' '--parseopt' '--' '--rebasing' '--resolvemsg= When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort". ' trace: built-in: git 'rev-parse' '--git-dir' trace: built-in: git 'rev-parse' '--show-prefix' trace: built-in: git 'rev-parse' '--show-toplevel' trace: built-in: git 'var' 'GIT_COMMITTER_IDENT' trace: built-in: git 'rev-parse' '--verify' '-q' 'HEAD' trace: built-in: git 'config' '--bool' '--get' 'am.keepcr' trace: built-in: git 'mailsplit' '-d4' '-o/home/schuettm/webroot/test-repo/.git/rebase-apply' '-b' '--' trace: built-in: git 'update-index' '-q' '--refresh' trace: built-in: git 'diff-index' '--cached' '--name-only' 'HEAD' '--' trace: built-in: git 'cat-file' '-t' '5290c010a2c88dc29a019cb8f08ece9162a6482c' trace: built-in: git 'cat-file' 'commit' '5290c010a2c88dc29a019cb8f08ece9162a6482c' trace: built-in: git 'config' 'i18n.commitencoding' trace: built-in: git 'show' '-s' '--pretty=raw' '--encoding=UTF-8' '5290c010a2c88dc29a019cb8f08ece9162a6482c' '--' trace: built-in: git 'diff-tree' '--root' '--binary' '--full-index' '5290c010a2c88dc29a019cb8f08ece9162a6482c' Applying: parent trace: built-in: git 'apply' '--build-fake-ancestor' '/home/schuettm/webroot/test-repo/.git/rebase-apply/patch-merge-tmp-index' '/home/schuettm/webroot/test-repo/.git/rebase-apply/patch' trace: built-in: git 'write-tree' Using index info to reconstruct a base tree... trace: built-in: git 'diff-index' '--cached' '--diff-filter=AM' '--name-status' 'HEAD' trace: built-in: git 'apply' '--cached' trace: built-in: git 'write-tree' Falling back to patching base and 3-way merge... trace: built-in: git 'merge-recursive' '4b825dc642cb6eb9a060e54bf8d69288fbee4904' '--' 'HEAD' 'bf8853bde213ddd00cb31b3d22906cf746dcc2fd' Auto-merging check.yml CONFLICT (add/add): Merge conflict in check.yml trace: built-in: git 'rerere' Failed to merge in the changes. Patch failed at 0001 parent trace: built-in: git 'config' '--bool' 'advice.amworkdir' The copy of the patch that failed is found in: /home/schuettm/webroot/test-repo/.git/rebase-apply/patch When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort". trace: built-in: git 'rev-parse' '--verify' '-q' 'HEAD' ,则不会发生冲突。

以下是运行两者的git命令的跟踪。

$:~/webroot/test-repo$ GIT_TRACE=1 git rebase                                                                                                                                                                            
trace: exec: 'git-rebase'
trace: run_command: 'git-rebase'
trace: built-in: git 'rev-parse' '--parseopt' '--'
trace: built-in: git 'rev-parse' '--git-dir'
trace: built-in: git 'rev-parse' '--is-bare-repository'
trace: built-in: git 'rev-parse' '--show-toplevel'
trace: built-in: git 'config' '--bool' 'rebase.stat'
trace: built-in: git 'config' '--bool' 'rebase.autostash'
trace: built-in: git 'config' '--bool' 'rebase.autosquash'
trace: built-in: git 'rev-parse' '--verify' 'refs/heads/parent^0'
trace: built-in: git 'rev-parse' '--verify' 'refs/heads/parent^0'
trace: built-in: git 'symbolic-ref' '-q' 'HEAD'
trace: built-in: git 'rev-parse' '--verify' 'HEAD'
trace: built-in: git 'merge-base' '--fork-point' 'refs/heads/parent' 'HEAD'
trace: built-in: git 'rev-parse' '--verify' 'HEAD'
trace: built-in: git 'update-index' '-q' '--ignore-submodules' '--refresh'
trace: built-in: git 'diff-files' '--quiet' '--ignore-submodules'
trace: built-in: git 'diff-index' '--cached' '--quiet' '--ignore-submodules' 'HEAD' '--'
trace: built-in: git 'merge-base' 'd29fb1b0ab2eefba0f8ef13fd4e37d61acb9ee6f' '75d8979d743ba575de680fd04d517aa74e813819'
First, rewinding head to replay your work on top of it...
trace: built-in: git 'checkout' '-q' 'd29fb1b0ab2eefba0f8ef13fd4e37d61acb9ee6f^0'
trace: built-in: git 'update-ref' 'ORIG_HEAD' '75d8979d743ba575de680fd04d517aa74e813819'
trace: built-in: git 'format-patch' '-k' '--stdout' '--full-index' '--ignore-if-in-upstream' '--src-prefix=a/' '--dst-prefix=b/' '--no-renames' '--no-cover-letter' '5290c010a2c88dc29a019cb8f08ece9162a6482c..75d8979d743ba575de680fd04d517aa7
4e813819'
trace: exec: 'git-am' '--rebasing' '--resolvemsg=
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
'
trace: run_command: 'git-am' '--rebasing' '--resolvemsg=
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
'
trace: built-in: git 'rev-parse' '--parseopt' '--' '--rebasing' '--resolvemsg=
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
'
trace: built-in: git 'rev-parse' '--git-dir'
trace: built-in: git 'rev-parse' '--show-prefix'
trace: built-in: git 'rev-parse' '--show-toplevel'
trace: built-in: git 'var' 'GIT_COMMITTER_IDENT'
trace: built-in: git 'rev-parse' '--verify' '-q' 'HEAD'
trace: built-in: git 'config' '--bool' '--get' 'am.keepcr'
trace: built-in: git 'mailsplit' '-d4' '-o/home/schuettm/webroot/test-repo/.git/rebase-apply' '-b' '--'
trace: built-in: git 'update-index' '-q' '--refresh'
trace: built-in: git 'diff-index' '--cached' '--name-only' 'HEAD' '--'
trace: built-in: git 'cat-file' '-t' '75d8979d743ba575de680fd04d517aa74e813819'
trace: built-in: git 'cat-file' 'commit' '75d8979d743ba575de680fd04d517aa74e813819'
trace: built-in: git 'config' 'i18n.commitencoding'
trace: built-in: git 'show' '-s' '--pretty=raw' '--encoding=UTF-8' '75d8979d743ba575de680fd04d517aa74e813819' '--'
trace: built-in: git 'diff-tree' '--root' '--binary' '--full-index' '75d8979d743ba575de680fd04d517aa74e813819'
Applying: child
trace: built-in: git 'write-tree'
trace: built-in: git 'rev-parse' '--verify' '-q' 'HEAD'
trace: built-in: git 'commit-tree' '4db00e2710f88742114576a8a7d5ee6875f433c3' '-p' 'd29fb1b0ab2eefba0f8ef13fd4e37d61acb9ee6f'
trace: built-in: git 'update-ref' '-m' 'rebase: child' 'HEAD' 'f7d50b6e381e0894904bd122d13c5880f8583916'
trace: built-in: git 'notes' 'copy' '--for-rewrite=rebase'
trace: built-in: git 'rev-parse' 'HEAD'
trace: built-in: git 'update-ref' '-m' 'rebase finished: refs/heads/child-1 onto d29fb1b0ab2eefba0f8ef13fd4e37d61acb9ee6f' 'refs/heads/child-1' 'f7d50b6e381e0894904bd122d13c5880f8583916' '75d8979d743ba575de680fd04d517aa74e813819'
trace: built-in: git 'symbolic-ref' '-m' 'rebase finished: returning to refs/heads/child-1' 'HEAD' 'refs/heads/child-1'
trace: built-in: git 'gc' '--auto'

git rebase

如果你盯着它看一段时间,问题就是git 'merge-base' '--fork-point' 'refs/heads/parent' 'HEAD'使用git rebase来确定合并基础,从手册页也使用reflog帮助,这可能就是为什么它接受修正并且不会因冲突而停止。

什么神奇的论据被传递给branch.<name>.remote,让它具有这个功能?

git rebase的手册页说明使用了branch.<name>.merge和{{1}}但是当我用git config查找它们后我替换了这些值时,我得到一个无效的上游错误,所以我猜他们在使用之前我在内部以某种方式扩展,我不明白。

2 个答案:

答案 0 :(得分:1)

你是对的,这是--fork-point魔法。这实际上是documented

  

如果&lt; upstream&gt;未指定,上游在分支中配置。&lt; name&gt; .remote和branch。将使用&lt; name&gt; .merge选项(有关详细信息,请参阅git-config(1)),并假设--fork-point选项。如果您当前不在任何分支上,或者当前分支没有配置上游,则rebase将中止。

您可以手动将--fork-point添加到您自己的rebase命令中以获得相同的效果。

--fork-point的行为并不是世界上最容易描述的行为,而且rebase文档链接到the git merge-base documentation。它有一个很好的图表,但在描述方面还有很多不足之处。

因为--fork-point依赖于reflog,所以只有在您的上游分支reflog保留关键信息时,它才有效。通常这是90天(可达提交到期)或30天(无法到达提交到期)。这个does not make it any easier to describe. :-)提及 intent 可能会有所帮助:它的目的是帮助从上游的rebase中恢复,它确实可以帮助你恢复。

答案 1 :(得分:0)

对于那些对我有更多了解的人,我会保持开放。但在阅读了调用变基的git-rebase.sh脚本之后,我发现由于某些原因--fork-point在没有args的情况下调用git rebase时会神奇地添加。因此git rebasegit rebase --fork-point parent-branch相同。