简体   繁体   中英

Git equivalent of hg purge

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?

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM