显示当前的git交互式rebase操作

时间:2017-07-20 20:30:25

标签: git

当处于交互式rebase的中间时,例如bind = "0.0.0.0:5000" workers = 4 并添加/编辑了一些提交,我经常对我正在编辑的提交感到困惑,特别是当出现合并冲突时:

git rebase -i HEAD~12

如何清楚了解当前状态中涉及的所有补丁?例如,什么是基本补丁,我正在“挑选”哪个补丁,合并冲突来自哪个补丁?

2 个答案:

答案 0 :(得分:2)

  

当处于交互式rebase的中间时,例如git rebase -i HEAD~12并添加/编辑一些提交,我经常对我正在编辑的提交感到困惑

使用Git 2.17(2018年第二季度),新的“--show-current-patch”选项为最终用户提供了在“git rebase”(和“git am”时应用差异的方法“)因冲突而停止。

commit fbd7a23commit 6633529commit 984913aNguyễn Thái Ngọc Duy (pclouds)(2018年2月11日)。 帮助:Tim Landscheidt (scfc)
(由Junio C Hamano -- gitster --合并于commit 9ca488c,2018年3月6日)

  

rebase:引入并使用伪ref ref REBASE_HEAD

     

新命令git rebase --show-current-patch对于查看非常有用   与当前rebase状态相关的提交   但是有些人可能会发现它背后的“git show”命令太有限了   你可能想要增加上下文行,做一个忽略空格的差异......

     

对于这些高级用例,用户可以执行任何命令   想要使用新的伪引用REBASE_HEAD

     

这也有助于显示停止提交的位置,这很难   从上一个实现--show-current-patch 的补丁中看到。

答案 1 :(得分:1)

如果您遇到冲突,可以运行git show查看上次应用的提交。

然后在打开冲突文件时,冲突将一方面显示上次应用提交时文件的状态,另一方面显示当前正在应用的提交时文件的状态。

示例:

我用文件“a”创建了一个repo。我的第一个提交是创建文件:

John@debian-John: ~/tmp/test (master #) ✖ (1)
> touch a
John@debian-John: ~/tmp/test (master #) ✔
> git add a
John@debian-John: ~/tmp/test (master +) ✔
> git commit -m initial
[master (root-commit) 298299e] initial
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a

然后,我修改了文件并将其作为“commit1”提交:

John@debian-John: ~/tmp/test (master) ✔
> echo aaa >a
John@debian-John: ~/tmp/test (master *) ✔
> git add a
John@debian-John: ~/tmp/test (master +) ✔
> git commit -m commit1
[master 90b49f8] commit1
 1 file changed, 1 insertion(+)

然后,再次为提交“commit2”完成:

John@debian-John: ~/tmp/test (master) ✔
> echo bbb >>a
John@debian-John: ~/tmp/test (master *) ✔
> git add a
John@debian-John: ~/tmp/test (master +) ✔
> git commit -m commit2
[master 14d798e] commit2
 1 file changed, 1 insertion(+)

然后我重新删除了commit1:

John@debian-John: ~/tmp/test (master) ✔
> git rebase -i HEAD^^
Auto-merging a
CONFLICT (content): Merge conflict in a
error: could not apply 14d798e... commit2

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".

Recorded preimage for 'a'
Could not apply 14d798e... commit2

无法应用Commit2,因为其上下文已更改(commit1缺失)。请注意具有commit2哈希的error: could not apply 14d798e... commit2。在冲突中,如果我运行git show,我会得到:

John@debian-John: ~/tmp/test (master *+|REBASE-i 1/1) ✖ (1)
> git show
commit 298299e3fb4e75c50aaa346c9f57c3b8885726f7 (HEAD)
Author: John Doe <john@doe>
Date:   Fri Jul 21 15:59:01 2017 +0100

    initial

diff --git a/a b/a
new file mode 100644
index 0000000..e69de29
John@debian-John: ~/tmp/test (master *+|REBASE-i 1/1) ✔
> git status
interactive rebase in progress; onto 298299e
Last command done (1 command done):
   pick 14d798e commit2
No commands remaining.
You are currently rebasing branch 'master' on '298299e'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

    both modified:   a

no changes added to commit (use "git add" and/or "git commit -a")

a的内容是:

John@debian-John: ~/tmp/test (master +|REBASE-i 1/1) ✔
> cat a
<<<<<<< HEAD
=======
aaa
bbb
>>>>>>> 14d798e... commit2

其中HEAD是应用的最后一次提交(初始),第二部分是未能应用的提交。

我希望它会有所帮助。