TortoiseGit Manual

Deleting, Moving and Renaming

Unlike CVS, Git allows renaming and moving of files and folders. So there are menu entries for delete and rename in the TortoiseGit submenu. However, unlike SVN Git does not track filenames. Git only tracks the content of files. So there is in general no need to use the Git rename or remove functionality or even to "repair renames" as in SVN. Renames and copies are automatically detected when showing the log. However, using the Git delete and move functionality the files are automatically removed from the Git index (i.e., not shown as missing, but deleted) and in case of move/rename also re-added with the new names (i.e., the new names don't show up as unversioned).

Figure 2.47. Explorer context menu for versioned files

Explorer context menu for versioned files


Deleting files and folders

Use TortoiseGitDelete to remove files or folders from Git.

When you TortoiseGitDelete a file, it is removed from your working tree immediately as well as being marked for deletion in the repository on next commit. Up until you commit the change, you can get the file back using TortoiseGitRevert on the parent folder or on the or the section called “Committing Your Changes To The Repository” or the section called “Getting Status Information” dialogs.

If you want to delete an item from the repository, but keep it locally as an unversioned file/folder, use Extended Context MenuDelete (keep local). You might have to hold the Shift key while right clicking on the item in the explorer list pane (right pane) in order to see this in the extended context menu.

Getting a deleted file or folder back

If you have deleted a file or a folder and already committed that delete operation to the repository, then a normal TortoiseGitRevert can't bring it back anymore. But the file or folder is not lost at all. If you know the revision the file or folder got deleted (if you don't, use the log dialog to find out) open the repository browser and switch to that revision. Then select the file or folder you deleted, right-click and select Context MenuRevert to this revision. Refer to the section called “The Repository Browser” and the section called “Log Dialog” to find out more.

Moving files and folders

If you want to do a simple in-place rename of a file or folder, use Context MenuRename... Enter the new name for the item and you're done.

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:

  1. select the files or directories you want to move

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

  3. release the right mouse button

  4. in the popup menu select Context MenuGit Move versioned files here

Do Not Git Move Submodule

You should not use the TortoiseGit Move or Rename commands on a folder which has been created using git submodule.

Changing case in a filename

Making case-only changes to a filename needs special attention, because Windows does not honor the filename casing by default. Therefore just renaming a file using the rename command of the Explorer is likely not to work. It is important to rename it using Git in order to update the index to make it use the new filename. Use the Rename... command in the TortoiseGit submenu.

Dealing with filename case conflicts

If the repository already contains two files with the same name but differing only in case (e.g. TEST.TXT and test.txt), you will not be able to commit, and only one of them can be checkout on a Windows client. Whilst Git (in general) supports case-sensitive filenames, Windows does not.

This sometimes happens when files are committed from a system with a case-sensitive file system, like Linux, or when the setting core.ignorecase is set to false (cf. git-config(1) man-page).

In that case, you have to decide which one of them you want to keep and delete the other(s) from the repository (or rename the other(s)). Easiest way is to do that on a case-sensitive file system, followed by committing and pushing the changes. Doing it on Windows requires several steps (and two commits):

Solution

  1. Delete the file in explorer.

    Caution

    Do NOT use the Delete or the Delete (keep local) command in the TortoiseGit submenu!

  2. Open the Commit dialog. (All the checked items are of Deleted status.)

  3. Uncheck only one item you want to keep.

  4. Commit the changes.

  5. Revert deletion of the wanted file in order to get it back. If you want to keep both or more files which had the "same" name, but with a different new name, do this for all files in question and rename them before proceeding with the next file.

Deleting Unversioned Files

Usually you set your ignore list such that all generated files are ignored in Git. But what if you want to clear all those ignored items to produce a clean build? Usually you would set that in your makefile, but if you are debugging the makefile, or changing the build system it is useful to have a way of clearing the decks.

TortoiseGit provides just such an option using Extended Context MenuClean up.... You may have to hold the Shift while right clicking on a folder in the explorer list pane (right pane) in order to see this in the context menu. This will show a dialog which lists all possible clean up options (cf. the section called “Cleanup”).