Search code examples
gitgithubgit-commitpull

Github PR wrongly Considering a File Add & Delete as File Move


I have the following setup in my GitHub

GitHub Main Repository: QAScript1.sql with oldData

GitHub Dev Repository : I have updated QAScript1.sql with newData, Added new file ProdScript1.sql with sameContents as QAScript1.sql and committed both these files - Commit1

Deleted the QAScript1.sql - Commit2

Raised a PR to merge from GitHub Dev Repository to Github Main Repository

Now when i see the PR ->Files Changed section,I see that QAScript1.sql -> ProdScript1.sql ,I undertand this as QAScript1.sql file has been moved to ProdScript1.sql

My Question is

i)They both are 2 different files - QAScript1.sql, ProdScript1.sql .Why Github is considering as file moved instead of considering it as new File Added and old file Deleted.

ii)How does Git recognizes a fileMove in the above case?


Solution

  • Git does not remember copies and renames. Instead, it detects them with heuristics. Git has decided QAScript1.sql and ProdScript1.sql are similar enough to probably have been a rename.

    Sometimes it's wrong. That's ok, there's no difference. The history of change is still there. Github is only showing you the final result of the merge. It doesn't matter if it was done with one git mv or over multiple commits as you've done.

    See git-diff's --find-renames and find-copies for more.