如何在Git中删除未跟踪的文件? [英] how to remove untracked files in Git?

查看:620
本文介绍了如何在Git中删除未跟踪的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个分支,说我从主分支中分支出来的实验分支。然后,我在实验分支中生成一个用户模型,但并未将它们添加到索引中。 b
$ b

如果我想放弃最近在实验分支中添加的文件的所有更改,我该怎么办?未跟踪的文件如下所示:

  $ git status 
在分支上new_chick
未记录的文件:
(使用git add< file> ...来包含将要提交的内容)

.project
app / models / user.rb
db / migrate /
test / fixtures / users.yml
test / unit / user_test.rb

我试图运行git reset --hard,希望能够取消所有这些更改,但上面的所有文件仍然显示。



任何人都应该舍弃一些对我有用吗?

解决方案

要删除未跟踪的文件/目录,请执行以下操作:

< pre $ git clean -fdx

-f - force

-d - 目录也是



-x - 也删除被忽略的文件(如果你不用,您想删除被忽略的文件)


I'm working on a branch, say "experimental" branch which I branch out from my master branch.Then, I generate a user model in experimental branch, but does not add them to index yet.

What do I have to do if I want to discard all the changes of the files recently added in my experimental branch? The untracked files are listed as below:

$ git status
 On branch new_chick
 Untracked files:
   (use "git add <file>..." to include in what will be committed)

       .project
       app/models/user.rb
       db/migrate/
       test/fixtures/users.yml
       test/unit/user_test.rb

I tried to run "git reset --hard" in hope to undo all those changes, but all the files above still show.

Anyone please shed some light on me?

解决方案

To remove untracked files / directories do:

git clean -fdx

-f - force

-d - directories too

-x - remove ignored files too ( don't use this if you don't want to remove ignored files)

这篇关于如何在Git中删除未跟踪的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆