Using 'git mv' to rename file logs as entire file contents being changed

42 Views Asked by At

I have a weird case where I try to track some changes made to a large code file retroactively, the person who made said file saved different versions of the file called mainV1.py, mainV2.py and mainV3.py.

I've placed the first file mainV1.py in the repository and commited it (let's call it commit 1), then made a name change using the git command git mv mainV1.py mainV2.py and commited that (commit 2) and then replaced the renamed mainV2.py with the actual mainV2.py file and commited that (commit 3).

I've done the same for mainV3.py, creating commit 4 (renaming) and commit 5 (replacing the renamed file with the new file).

All this was done to be able to track the changes between V1, V2 and V3 easily within the repository.

The problem i encounter is that when I look at the diff between commit 1 and commit 2 and commit 3 and commit 4, the change is marked to be the entire contents of the file (even though it's marked as a rename in git). This means that even though the diff between commit 2 and commit 3 clearly shows only the relevant line changes, when I diff between commit 1 and commit 3 I only see changes made to the entire contents of the file.

This also has the effect that when I use git log --follow -- mainV3.py I only get the 3 commits commit 1, commit 3, commit 5 listed.

This is the current state of things. which means that I sort of have the changes made to the file tracked in the repository, but i can't for example see the full changes between mainV3.py and mainV1.py since that is a diff between commit 1 and commit 5 and that shows up a full file rewrite.

Anyone knows where I went wrong?

0

There are 0 best solutions below