Remember one thing: Git tracks file content only.
From Moving Files section of Pro Git book v2:
Unlike many other VCS systems, Git doesn’t explicitly track file movement. If you rename a file in Git, no metadata is stored in Git that tells it you renamed the file. However, Git is pretty smart about figuring that out after the fact
And, moving and rename is the same thing in Git.
So, Git detects the moving/rename automatically only works under the premise that those files are not modified.
Git does these things when you moving/rename file only:
- A tracked file is deleted, git gets the SHA-1 of that file content, assume the value is
- A untrack file is added, git calculates the SHA-1 of that file content, assume the value is
- If you commit at this moment, git will figure out they have the same SHA-1 value, then treat them as a rename.
Suppose you modified some tracked files and also moving them into other folder. Then, unfortunately, git can not detect them as rename/moving automatically when commit.
If you really want git to track rename/moving automatically, you need to do:
Make sure you DO NOT modify the file(s) and only rename/move file(s) in one commit.
If you want to modify file and move file at the same time, and want git to detect them as rename/moving by using TortoiseGit, then in your case:
- Right click on that file, and click
TortoiseGit -> Rename... item of context menu.
new_folder\ to the filename, see:
Note: you need to rename files one by one. Suppose lot of work to do. So, better rename file only.
Note2: If you modify a lot on file, git can not figure out it is a rename/moving.