0

I found git clean -xdf. And I like it, because it cleans up what may IDE created.

Today I was asked by a coworker: Can git clean move files to recycle bin instead of deleting the files?

I checked, git clean deleted some files in a test repository, but didn't move the files to trash.

I know there is option -n for dryrun.

Edit:

I'm on Windows 10 - that's why I have a recycle bin :).
And im using Git from PowerShell with PoSh-Git extension (to get auto completion).

Paebbels
  • 15,573
  • 13
  • 70
  • 139

2 Answers2

2

Here is a recipe for a unix alias that does exactly that. https://coderwall.com/p/g16jpq/keep-your-git-directory-clean-with-git-clean-and-git-trash

You could probably adapt it to powershell pretty easily. It seems like the core is

git ls-files --others --exclude-standard

which will list your untracked files. I'm not a PowerShell expert however so I'll decline to make an alias myself.

Also, from what I can tell there is no soft option native to git clean.

sakurashinken
  • 3,940
  • 8
  • 34
  • 67
1

This is pretty fragile, (and isn't git recycling the file) but:

foreach ($s in git clean -xdn) {Remove-ItemSafely -Force $s.Remove(0,13)}

Caveats:

1) It'll just delete the file if there's no Recycle Bin for the drive. 2) It'll break if the output of git clean -xdn changes because $s.Remove(0,13) is removing the first 13 characters of each line of output. 3) You may have to run Install-Module Recycle as an administrator on any given machine first.

A git plugin that returns .NET objects is preferable for something like this. (Because then you could remove-itemsafely $s.FileName, for example)

zzxyz
  • 2,953
  • 1
  • 16
  • 31