Steven Steven - 2 months ago 7
Git Question

Not expected log after renaming a file in git

I renamed a file in a git repository with:

git mv oldname.py newname.py


then
git status
gave me that the changes need to be committed are renaming the file.(I didn't write
git add newname.py
)
I committed then pushed to GitHub and the file named was changed successfully.
But when I opened the file on GitHub and saw it's history it was containing only the last commit not all of its commits.

Can someone please explain to me what happened?

Answer

Git doesn't move history of edits in a file when you move. It would create a huge set of problems when doing patching, reverting commits etc. git mv is a shortcut for removing file and adding to list of tracked files.

GitHub doesn't show complete history of files but you can do it manually with git log --follow newname.py, it should show changes before git mv

Comments