-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?

Little Helper
  • 1,870
  • 3
  • 12
  • 20
Steven Sorial
  • 121
  • 2
  • 9

2 Answers2

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.

MayeulC
  • 1,628
  • 17
  • 24
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

agilob
  • 6,082
  • 3
  • 33
  • 49