In the scenario where the first commit, is adding file X, second commit, you remove X and the third commit you re-add it.
If you run git diff, then you get X deleted, X added.
Is there a way to analyse this set of changes and get the result, "no change" ?
I am actually interested in the line changes, in my real example, I get this response:
index 5988d3c..eaf3238 100644
--- a/.babelrc
+++ b/.babelrc
@@ -1,3 +1,3 @@
-{
- "presets": ["es2015", "stage-0"]
-}
+{
+ "presets": ["es2015", "stage-0"]
+}
which seems to show the exact same lines added and subtracted.
Here is the output of diff -R
--- b/.babelrc
+++ a/.babelrc
@@ -1,3 +1,3 @@
-{
- "presets": ["es2015", "stage-0"]
-}
+{^M
+ "presets": ["es2015", "stage-0"]^M
+}^M
You can simply do git diff [first commit] [third commit] and this will return no difference.
For example here is the git log of my test repository.
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.
When I compare the first and third commits using git diff 681f117fd095c7a99d631a1819db855d7fd9e6e8 368c6c0bc4169b8f482761b036da2284f937579d the result is empty.
However if I compare the first and second commit using git diff 681f117fd095c7a99d631a1819db855d7fd9e6e8 54d9885f860b56c34718387206397c703eb37b36 the result is:
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.
If you aren't getting an empty change set but the lines read the same then there must be some difference in characters within the line, for example a tab being used instead of a space or a different line ending.
You can use git diff -w to ignore white space when performing the diff. Documentation: https://git-scm.com/docs/git-diff
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With