-1

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 and pushed to GitHub, then the name of the file was changed successfully. But when I saw the history of the file on GitHub, it was containing only the last commit, not all of its commits.

Can someone please explain to me what happened?

0

2 Answers 2

0

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

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

Comments

0

git mv a b automatically adds the renamed file b to the staging area. This is effectively the same as doing

mv a b git rm a git add b 

or

cp a b git rm a git add b 

In this case, one can clearly see why some clients such as GitHub's web interface would consider those two files as separate.

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.