gpt4 book ai didi

git - 你能得到两个 git 提交之间的实际差异吗?

转载 作者:太空狗 更新时间:2023-10-29 14:05:04 25 4
gpt4 key购买 nike

在第一次提交添加文件 X 的情况下,第二次提交删除 X,第三次提交重新添加它。

如果你运行 git diff,那么你会删除 X,添加 X。

有没有办法分析这组变化并得到结果“没有变化”?

我实际上对线路变化很感兴趣,在我的真实例子中,我得到了这样的回应:

index 5988d3c..eaf3238 100644
--- a/.babelrc
+++ b/.babelrc
@@ -1,3 +1,3 @@
-{
- "presets": ["es2015", "stage-0"]
-}
+{
+ "presets": ["es2015", "stage-0"]
+}

这似乎显示了添加的完全相同的行。

编辑:

这是 diff -R 的输出

--- b/.babelrc
+++ a/.babelrc
@@ -1,3 +1,3 @@
-{
- "presets": ["es2015", "stage-0"]
-}
+{^M
+ "presets": ["es2015", "stage-0"]^M
+}^M

最佳答案

您可以简单地执行 git diff [first commit] [third commit],这不会返回任何差异。

例如,这里是我的测试存储库的 git log

commit 368c6c0bc4169b8f482761b036da2284f937579d
Author: Adam
Date: Fri May 6 10:17:45 2016 +0100

Edited file back.

commit 54d9885f860b56c34718387206397c703eb37b36
Author: Adam
Date: Fri May 6 10:16:51 2016 +0100

Edited file.

commit 681f117fd095c7a99d631a1819db855d7fd9e6e8
Author: Adam
Date: Fri May 6 10:16:09 2016 +0100

Added file.

当我使用 git diff 681f117fd095c7a99d631a1819db855d7fd9e6e8 368c6c0bc4169b8f482761b036da2284f937579d 比较第一次和第三次提交时,结果为空。

但是,如果我使用 git diff 681f117fd095c7a99d631a1819db855d7fd9e6e8 54d9885f860b56c34718387206397c703eb37b36 比较第一次和第二次提交,结果是:

diff --git a/file.txt b/file.txt
index c9a0e4f..76af740 100644
--- a/file.txt
+++ b/file.txt
@@ -1,6 +1,6 @@
I won't edit this line.

-I will edit this line.
+I have edited this line.

I won't edit this line.

如果您没有得到一个空的更改集,但行读取相同,那么行内的字符一定存在一些差异,例如使用制表符而不是空格或不同的行结尾。

您可以使用 git diff -w 在执行 diff 时忽略空白。文档:https://git-scm.com/docs/git-diff

希望对您有所帮助。

关于git - 你能得到两个 git 提交之间的实际差异吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37067937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com