我如何从当前工作树中删除未跟踪的本地文件 ?
当前回答
我喜欢git stash push -u
因为你可以用git stash pop
.
我还找到了一种方法 在藏物中显示未追踪的文件(例如:git show stash@{0}^3
) https://stackoverflow.com/a/12681856/338986
内容2:git stash save
将作有利于push
谢谢 @timp-wolf.
其他回答
如果未跟踪的目录是自有的 git 仓库( 如子模块) , 您需要使用-f
两次:
git clean -d -f -f
git-清洁这是您正在寻找的。 它用于从工作树上移除未跟踪的文件 。
git clean -f -d -x $(git rev-parse --show-cdup)
对根目录应用干净, 无论您在仓库目录树中将其命名为哪里。 我总是使用它, 因为它不会迫使您离开您现在工作所在的文件夹, 并允许您从所在位置清除并承诺 。
确定该旗帜-f
, -d
, -x
匹配您的需要 :
-d
Remove untracked directories in addition to untracked files. If an
untracked directory is managed by a different Git repository, it is
not removed by default. Use -f option twice if you really want to
remove such a directory.
-f, --force
If the Git configuration variable clean.requireForce is not set to
false, git clean will refuse to delete files or directories unless
given -f, -n or -i. Git will refuse to delete directories with .git
sub directory or file unless a second -f is given. This affects
also git submodules where the storage area of the removed submodule
under .git/modules/ is not removed until -f is given twice.
-x
Don't use the standard ignore rules read from .gitignore (per
directory) and $GIT_DIR/info/exclude, but do still use the ignore
rules given with -e options. This allows removing all untracked
files, including build products. This can be used (possibly in
conjunction with git reset) to create a pristine working directory
to test a clean build.
还有其他的旗帜 也有其他的,只是检查git clean --help
.
注意: 第一次浏览到目录并检查您想要清除的分支 。
-i
交互式模式,它将告诉您要删除什么, 您可以从列表中选择一个动作 。
清洁文件 文件仅[不列出文件夹,也不清洗]:
$ git clean -i
清洁文件和文件夹:
$ git clean -d -i
-d
包括目录。
如果您选择了c
从列表中删除。文件/文件夹将被删除,因为文件/文件夹没有被跟踪,还会删除被你弄乱的文件/文件夹。 *
例如:如果您对远程的文件夹进行重组,并将修改拉到本地计算机中。其他人最初创建的文件/文件夹将放在过去的文件夹和您重组的新文件夹中。
清除未跟踪文件的简单方式
要删除所有未跟踪的文件,简单的方法就是先加全部和重置重置( R)如下所示
git add --all
git reset --hard HEAD
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式