Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git equivalent of hg purge

Tags:

git

mercurial

Not just the command, but the actual behavior... hg purge will delete all untracked files.

I thought it was git clean, but nope...

$ git clean
fatal: clean.requireForce defaults to true and neither -n nor -f given; refusing to clean

$ git clean -n
Would not remove src/

$ git clean -f
Not removing src/

So, it feels like git just told me to go f*** myself, lol... I'm not asking this thing if it agrees, I just want Git to do what I ask of it.

How do I convince Mr. Git to please do me the favor of removing my untracked files?

like image 402
dukeofgaming Avatar asked Sep 14 '13 19:09

dukeofgaming


People also ask

What is HG purge?

2. 27. hg purge --all will delete all un-tracked and ignored files. This is useful for cleaning up in-source builds. – tacaswell.

Does git clean delete files from computer?

git clean removes untracked files from the working directory. It does not remove files that have been committed. To do that you would use git rm . So if your git repo is at the root of your hard drive, then running git clean -df would remove all the files from your disk that aren't committed.


2 Answers

If you want to also remove directories, run git clean -f -d

If you just want to remove ignored files, run git clean -f -X

If you want to remove ignored as well as non-ignored files, run git clean -f -x

Note the case difference on the X for the two latter commands.

EDIT: useful linkie bout this git operation :)

like image 141
Dmitry Matveev Avatar answered Oct 20 '22 12:10

Dmitry Matveev


Here is a quick translation:

  • hg purge translates to git clean -f -d (deletes only untracked files and directories)
  • hg purge --all translates to git clean -f -d -x (also deleted ignored files)

Git also has git clean -f -X (upper case X) which only deletes ignored files but leaves untracked files untouched. Mercurial has no equivalent for this.

like image 10
Sebastian Krysmanski Avatar answered Oct 20 '22 12:10

Sebastian Krysmanski