TortoiseGit: Moving files to new folder not recognized as move

I'm trying to move some files in my repository to a new folder. I want git / TortoiseGit to recognize that this is a move instead of a delete and multiple adds.
How can I make this work? I checked the documentation of TortoiseGit and searched Google but that didn't seem to be very useful.

So, what I have is this structure:

repo_root/somefile.txt

What I want:

repo_root/new_folder/somefile.txt

Of course "somefile.txt" represents all files and folders that are being moved.


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:

  1. A tracked file is deleted, git gets the SHA-1 of that file content, assume the value is abc.
  2. A untrack file is added, git calculates the SHA-1 of that file content, assume the value is abc, too.
  3. 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:

  1. Right click on that file, and click TortoiseGit -> Rename... item of context menu.
  2. prefix new_folder\ to the filename, see: enter image description here
  3. commit

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.


From the TortoiseGit documentation:

If you want to move files around inside your working tree, perhaps to a different sub-folder, you can use the right-mouse drag-and-drop handler:

A. select the files or directories you want to move

B. right-drag them to the new location inside the working tree

C. release the right mouse button

D. in the popup menu select Context Menu → Git Move versioned files here