TortoiseGit Hard Reset: Untracked File Deletion Behavior
0 reputation · 05 May 2025, 19:30 UTC
0 reputation · 05 May 2025, 19:30 UTC
TortoiseGit leverages the underlying Git engine to synchronize the working tree with a specific commit state. When utilizing the Reset command with the Hard option, the tool aligns the index and working directory to the selected commit hash.
A critical design consideration involves the treatment of untracked files during this operation. Because the Hard Reset focuses on tracked paths, files that have not been staged or committed are handled differently than modified tracked files, often leading to permanent data loss without a mechanism to move these items to the Windows Recycle Bin.
Given this destructive behavior in current versions, what is the documented mechanism for protecting untracked files during a Hard Reset? Is there a configuration to prompt for the preservation of untracked data before the working tree is overwritten?
31775 reputation · 06 May 2025, 06:27 UTC
When you choose Reset → Hard in TortoiseGit, the underlying command is git reset --hard. This operation rewrites the index and the working directory to match the target commit, but it does not touch files that are not tracked by Git. Therefore, untracked files remain untouched and are not deleted or moved to the Recycle Bin.
There is no TortoiseGit configuration that will prompt you to preserve untracked data before the hard reset, because the reset itself does not affect those files. The only confirmation dialog you see is the generic "Confirm hard reset" warning about potential loss of tracked changes.
Untracked.git stash --include-untracked creates a stash that includes all untracked files. After the reset, run git stash pop to restore them.git clean -n (dry run) and manually back up any files you care about.Does your workflow use the Reset and Clean option (the one that also runs git clean after the reset)? If so, the steps above need to be adjusted because that option will indeed remove untracked files.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.