0

master is a branch with no files, while init is a branch with several files.

This is depicted in a couple of ways:

[17/09/21 7:38:18] ➜ atlantis-poc git:(init) g checkout master Switched to branch 'master' Your branch is up to date with 'origin/master'. [17/09/21 7:38:22] ➜ atlantis-poc git:(master) ls -al total 16 drwxrwxr-x 3 pkaramol pkaramol 4096 Σεπ 17 19:38 . drwxrwxr-x 7 pkaramol pkaramol 4096 Σεπ 16 16:39 .. drwxrwxr-x 8 pkaramol pkaramol 4096 Σεπ 17 19:38 .git -rw-rw-r-- 1 pkaramol pkaramol 181 Σεπ 16 16:39 .gitignore [17/09/21 7:38:25] ➜ atlantis-poc git:(master) g push -u origin init Warning: Permanently added 'github.com,140.82.121.4' (RSA) to the list of known hosts. Branch 'init' set up to track remote branch 'init' from 'origin'. Everything up-to-date [17/09/21 7:38:29] ➜ atlantis-poc git:(master) g checkout init Switched to branch 'init' Your branch is up to date with 'origin/init'. [17/09/21 7:38:32] ➜ atlantis-poc git:(init) ls -al total 52 drwxrwxr-x 5 pkaramol pkaramol 4096 Σεπ 17 19:38 . drwxrwxr-x 7 pkaramol pkaramol 4096 Σεπ 16 16:39 .. -rw-rw-r-- 1 pkaramol pkaramol 655 Σεπ 17 19:38 atlantis.yaml -rw-rw-r-- 1 pkaramol pkaramol 25 Σεπ 17 19:38 CODEOWNERS drwxrwxr-x 8 pkaramol pkaramol 4096 Σεπ 17 19:38 .git -rw-rw-r-- 1 pkaramol pkaramol 181 Σεπ 16 16:39 .gitignore -rw-rw-r-- 1 pkaramol pkaramol 11344 Σεπ 17 19:38 LICENSE.txt drwxrwxr-x 4 pkaramol pkaramol 4096 Σεπ 17 19:38 live drwxrwxr-x 4 pkaramol pkaramol 4096 Σεπ 17 19:38 modules -rw-rw-r-- 1 pkaramol pkaramol 6640 Σεπ 17 19:38 README.md [17/09/21 7:38:34] ➜ atlantis-poc git:(init) g push -u origin init Warning: Permanently added 'github.com,140.82.121.4' (RSA) to the list of known hosts. Branch 'init' set up to track remote branch 'init' from 'origin'. Everything up-to-date 
[17/09/21 7:39:13] ➜ atlantis-poc git:(init) g diff origin/master --name-only CODEOWNERS LICENSE.txt README.md atlantis.yaml live/non-prod/account.hcl live/non-prod/us-east-1/qa/env.hcl live/non-prod/us-east-1/qa/mysql/terragrunt.hcl live/non-prod/us-east-1/qa/webserver-cluster/terragrunt.hcl live/non-prod/us-east-1/region.hcl live/non-prod/us-east-1/stage/env.hcl live/non-prod/us-east-1/stage/mysql/terragrunt.hcl live/non-prod/us-east-1/stage/webserver-cluster/.terraform.lock.hcl live/non-prod/us-east-1/stage/webserver-cluster/terragrunt.hcl live/prod/account.hcl live/prod/us-east-1/prod/env.hcl live/prod/us-east-1/prod/mysql/.terraform.lock.hcl live/prod/us-east-1/prod/mysql/terragrunt.hcl live/prod/us-east-1/prod/webserver-cluster/terragrunt.hcl live/prod/us-east-1/region.hcl live/terragrunt.hcl modules/asg-elb-service/README.md modules/asg-elb-service/dependencies.tf modules/asg-elb-service/main.tf modules/asg-elb-service/outputs.tf modules/asg-elb-service/vars.tf modules/mysql/README.md modules/mysql/main.tf modules/mysql/outputs.tf modules/mysql/vars.tf (END) 
[17/09/21 8:21:30] ➜ atlantis-poc git:(init2) git rev-parse master origin/master init origin/init e48366b6fd95506a547525e12dce3c96ca823b58 e48366b6fd95506a547525e12dce3c96ca823b58 16a9e14ae65fb62d25a4221a92440f7efe01fe74 16a9e14ae65fb62d25a4221a92440f7efe01fe74 

Under these circumstances, how is it possible that the master <-- init comparison shows no diff on GitHub?

enter image description here

enter image description here

enter image description here

4
  • When viewed on GitHub, which of the branches master and init has no files, and which one does have files? Commented Sep 17, 2021 at 16:48
  • added relevant screenshots Commented Sep 17, 2021 at 16:55
  • For sanity purposes, git rev-parse master origin/master init origin/init will show you the tip commit IDs of your 4 branches to confirm which ones are actually the same. Commented Sep 17, 2021 at 17:16
  • added the output in the original question, just above the screenshots Commented Sep 17, 2021 at 17:22

1 Answer 1

2

Although I can't be sure, there are a few clues in your screenshots as to what's going on here.

  • "init" is shown as "1 commit ahead, 1 commit behind master"
  • both branches have 79 commits
  • the most recent commit message on "master" is the word "clearing"; this is the "1 commit behind"
  • the most recent commit message on "init" is "allow empty"; this is the "1 commit ahead"
  • the diff view shows no files changed, but 1 commit

The important thing to keep in mind is that a merge in git (and in any version control system) represents applying changes from one branch to another, not making two branches look the same. The "compare" option in Github is previewing this merge - note the title is "Comparing changes", not "comparing revisions".

It may be easier to picture if we imagine each branch represents the work of a different person. So, in your case, we can imagine:

  • there are 78 commits which already existed
  • Alice added one commit, "clearing", and called the result "master"
  • Bob added a different commit, "allow empty", and called the result "init"

"Comparing changes between master and init" therefore means finding what changes Bob has made (on "init") which Alice doesn't already have (on "master"). This gives us the single commit, with the message "allow empty".

Now the part that I'm guessing:

  • Alice's commit on "master" is what deleted all the files. Nothing Bob did on "init" is going to "undo" this change.
  • Bob's commit on "init" didn't actually change anything, as the message suggests. If it did change something (other than the one remaining file, .gitignore), you would get a conflict, because git would try to apply Bob's change after Alice's, and find that the file to modify was no longer there.

If you want to undo the deletion on "master", you need to do that explicitly - either create a commit bringing everything back (e.g. with git revert) or rewrite history so that the commit never happened (e.g. with careful use of git reset and git push --force-with-lease).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.