假设我刚刚将分支 foo
重新设置为 master
的基础,但有冲突。我想确保我没有在冲突解决期间通过引入额外更改或丢失更改(除了适合冲突解决的内容之外)而意外损坏 foo
的内容。我通过以下方式完成了此操作:
diff -u <(git diff `git merge-base master foo@{1}` foo@{1}) \
<(git diff `git merge-base master foo ` foo )
(更新:或我刚刚被提醒的 git-diff
的等效 ...
语法:)
diff -u <(git diff master...foo@{1}) <(git diff master...foo) | mate
这向我展示了 master..foo
发生的所有更改,这些更改被视为补丁,这正是我想要检查的最小值。然而,调用很复杂,输出也不是完全易于解释的。
有没有更好的方法来完成这项任务——提供相同的信息,但使用更好的方法或格式——还是我应该把上面的内容放在脚本中?
最佳答案
甚至比 interdiff
更好,现在 Git 2.19(2018 年第 3 季度)你有 git range-diff
。
参见“Git diff - two disjoint revision ranges”
git range-diff
documentation includes the following example :
When a rebase required merge conflicts to be resolved, compare the changes introduced by the rebase directly afterwards using:
$ git range-diff @{u} @{1} @
A typical output of
git range-diff
would look like this:------------ -: ------- > 1: 0ddba11 Prepare for the inevitable! 1: c0debee = 2: cab005e Add a helpful message at the start 2: f00dbal ! 3: decafe1 Describe a bug @@ -1,3 +1,3 @@ Author: A U Thor <author@example.com> -TODO: Describe a bug +Describe a bug @@ -324,5 +324,6 This is expected. -+What is unexpected is that it will also crash. ++Unexpectedly, it also crashes. This is a bug, and the jury is ++still out there how to fix it best. See ticket #314 for details. Contact 3: bedead < -: ------- TO-UNDO ------------
In this example, there are 3 old and 3 new commits, where the developer:
- removed the 3rd,
- added a new one before the first two, and
- modified the commit message of the 2nd commit as well its diff.
When the output goes to a terminal, it is color-coded by default, just like regular
git diff
's output. In addition, the first line (adding a commit) is green, the last line (deleting a commit) is red, the second line (with a perfect match) is yellow like the commit header ofgit show
's output, and the third line colors the old commit red, the new one green and the rest likegit show
's commit header.
在 Git 2.20 中,颜色可以更好地支持新的(范围)差异
参见 commit 2543a64 , commit 8d5ccb5 , commit 7648b79 (2018 年 8 月 17 日),和 commit 4441067 , commit f103a6f , commit 29ef759 , commit 017ac45 , commit 9d1e16b , commit 84120cc , commit c5e64ca , commit 991eb4f (2018 年 8 月 14 日)Stefan Beller (stefanbeller
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 30035d1 ,2018 年 9 月 17 日)
range-diff
: indent special lines as contextThe range-diff coloring is a bit fuzzy when it comes to special lines of a diff, such as indicating new and old files with
+++
and---
, as it would pickup the first character and interpret it for its coloring, which seems annoying as in regular diffs, these lines are colored bold viaDIFF_METAINFO
.By indenting these lines by a white space, they will be treated as context which is much more useful, an example on the range diff series itself:
git range-diff pr-1/dscho/branch-diff-v3...pr-1/dscho/branch-diff-v4
(来自存储库 github.com/gitgitgadget/git
)
[...] + diff --git a/Documentation/git-range-diff.txt b/Documentation/git-range-diff.txt + new file mode 100644 + --- /dev/null + +++ b/Documentation/git-range-diff.txt +@@ ++git-range-diff(1) [...] + diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile [...]
The first lines that introduce the new file for the man page will have the '
+
' sign colored and the rest of the line will be bold.The later lines that indicate a change to the
Makefile
will be treated as context both in the outer and inner diff, such that those lines stay regular color.
关于git - 比较 Git 中 rebase 的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12465184/