Question
I have a git repo on GitHub (demo), which has 3 branches:
main
: a default branchbranch-modify
: branched bymain
, contains a modifying commit tomain
branch-revert
: branched bybranch-modify
, contains another commit reverting the modifying commit
On this repo, I made a PR with branch-modify
against main
and merged with a merged commit (#1).
Also I made another PR with branch-revert
against main
(#2).
I expected the second PR shows diff reverting the change by the modifying commit.
However, GitHub shows empty diff.
Why did the diff end up empty? If this is an intended behavior, what is the rational behind it?
Git graph of repo after the operations:
% git log --all --oneline --graph
* 97d2b9b (HEAD -> main, origin/main) Merge pull request #1 from nekomachi-touge/branch-modify
|
| | * 6d23f11 (origin/branch-revert, branch-revert) Revert "modify test.txt"
| |/
| * eaec7f6 (origin/branch-modify, branch-modify) modify test.txt
|/
* c1f094b add test.txt
Prior research
I found similar questions:
- git compare doesnt show any difference
- Github showing an incorrect diff between main branch and PR branch
Both suggest the difference between two-dot and three-dot diffs, but I don’t spot any difference in my case.
% git diff main..branch-revert
diff --git a/test.txt b/test.txt
index 55b5f1f..323fae0 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-foofoo
+foobar
% git diff main...branch-revert
diff --git a/test.txt b/test.txt
index 55b5f1f..323fae0 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-foofoo
+foobar
Also, I found the “Comparing changes” function produce diffs not converse if I compare main
to branch-revert
then swap the branches:
https://github.com/nekomachi-touge/github-revert-test-20240814/compare/main…branch-revert
https://github.com/nekomachi-touge/github-revert-test-20240814/compare/branch-revert…main
Background
In my work, I have an IaC repo controlling two clusters with active/standby-style redundancy.
To switch active cluster, I need to make a change in the repo.
I wanted to test the redundancy by making a PR then reverting it with another PR.
However, after merging the former PR, the diff of the latter PR became empty, which was totally unexpected.
Trying to reproduce and understand the issue led me into posting this question.