Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-interactive "git clean -fdx"

Tags:

git

windows

I'm building a thing that processes incoming file packages, but I have the rather serious problem that I can't sanitize the incoming data until it's in a position to break the processing, and it breaks it such a way that simply restarting the process doesn't fix it.

My current best solution is to git clean -fdx and git checkout . the project directory the process uses, which works like a charm, except that sometimes git clean asks for user input ("cannot unlink file. Retry?"), which causes a problem for automation.

Is there a way to put Git into a non-interactive mode? I need to do this from inside Ruby on a Windows machine.

like image 781
Narfanator Avatar asked Oct 28 '13 08:10

Narfanator


People also ask

What is git clean command?

To recap, git clean is a convenience method for deleting untracked files in a repo's working directory. Untracked files are those that are in the repo's directory but have not yet been added to the repo's index with git add .

How do I undo changes in untracked files?

git reset --hard is a classic command in this situation - but it will only discard changes in tracked files (i.e. files that already are under version control). To get rid of new / untracked files, you'll have to use git clean !

Does git clean delete files?

'Git clean' examples Because the clean operation permanently deletes files, Git wants you to first run the command with the -n option to force a dry run. Remember that 'git clean' only removes untracked files.

What does git clean Xdf do?

git clean -xdf is a great "sh*t hit the fan" command. It erases each and every file in your git directory which is NOT part of your repository. All additional files, such as the ones listed in your . gitignore , will be removed.


2 Answers

yes no | git clean -fdx

yes no outputs no forever and piping that into git clean causes every prompt to be answered with no.

like image 21
ninjeff Avatar answered Sep 18 '22 13:09

ninjeff


For Windows, this is what worked for me (sets the GIT_ASK_YESNO environment variable to false, stopping git from asking yes-no questions):

set GIT_ASK_YESNO=false

Then when I get those same messages as warnings but it continues as if I said no.

So git clean -fdx works for me as expected without blocking.

like image 134
user1689716 Avatar answered Sep 17 '22 13:09

user1689716