7

I would feel much more comfortable using git clean if I knew I could undo the deletion in case something goes wrong.

Does it support Recycle Bin in any way, shape or form? If no, are there any workarounds that anyone knows of, such as an external tool using git clean -n to print out the files, and then moving them to Recycle Bin?

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • I bet git has some hooks for it, but even if not - I'm pretty sure that if you can list the files with `git clean -n`, then you can simply pipe the list to some mass-move tool that will move them to trashbin or whatever place you want. If that's possible, then you can write small script that does exactly that, name it git-trash and use it instead. – quetzalcoatl Jul 10 '14 at 08:41
  • 2
    @quetzalcoatl That gives me an idea, maybe `git clean -n | xargs trash-cli` would work for Linux. – sashoalm Nov 17 '14 at 17:12
  • https://stackoverflow.com/a/14283266/ – General Grievance Apr 17 '23 at 18:05

3 Answers3

3

Put recycle.exe into your %PATH%

Run git config --global alias.recycle !git_recycle.sh

Put git_recycle.sh in your %PATH%:

#!/bin/bash

cd ${GIT_PREFIX:-.}
git clean -xdfn "$@" | sed 's/Would remove //' | xargs -d \\n --no-run-if-empty recycle
Community
  • 1
  • 1
Kevin Smyth
  • 1,892
  • 21
  • 22
  • 1
    Exclamation mark has special meaning in Bash (refers to last command starting with the text after '!'). You should escape exclamation mark to make it working: `git config --global alias.recycle \!git_recycle.sh` – Paweł Stankowski Jun 06 '16 at 08:56
  • 1
    @PawełStankowski: good point, the given `git config` command works under `cmd.exe` but not bash. – Kevin Smyth Jul 01 '16 at 16:17
0

No.

If you're worried about losing files, you a "dry run" is really the only viable option:

git clean -n

or equivalently

git clean --dry-run

Git has no knowledge of the underlying desktop environment, and probably never will.

Git GUIs are capable of showing you these files, but why on earth would you want to move them to the recycle bin in the first place? Just think about what you're doing before removing files.

Alternatively, add the files to a seperate branch in your repository, although that probably defeats the purpose of deleting them in the first place.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • 2
    "Just think about what you're doing before removing files." If you consider the Recycle Bin, Trash Can, Undo (in Word, Gmail, etc), I'd guess that these were designed because many people find it stressful to have no recourse if they make a mistake. Not mention the number of times people do `git commit -am Checkpoint` – Kevin Smyth Jun 10 '15 at 15:07
  • @KevinSmyth Yes. And it's not just a psychological benefit; it lets you work faster, because you don't need to "double check" the actions as much -- you can always just go back. It's similar to "undo" in a word processor. Is it faster to make sure you always type things correctly the first time? Or is it faster to just type what you think is correct, and then use undo if you get it wrong? The latter's clearly better, at least in many cases. The same is true for the recycling bin. (albeit, to a much lower degree since git clean is much less common -- the principle is the same, however) – Venryx Apr 07 '17 at 05:34
-1

If you use Git Bash on Windows the quickest way is probably

explorer .

This will open the Explorer in the cwd. Find the file, hit DEL to delete and close the window with CTRL+W.

There's not even a confirmation prompt if depending on your explorer settings.

maxbe
  • 1
  • 1