如何快速备份要通过git clean删除的未跟踪文件? [英] How to make quick backup of untracked files which I want to delete by git clean?
问题描述
我有很多未跟踪的文件.我很确定我可以删除其中的大多数内容,但是...您知道,备份可能会有所帮助;)
I have a lot of untracked files. I am pretty sure that most of them I can delete, however... you know, backup could be helpful ;)
在类似情况下您正在做什么?
What you are doing in similar situation?
推荐答案
以下命令将在您的主目录中创建目录中所有未跟踪(但不忽略)的tar存档:
The following command will create a tar archive in your home directory of all of the untracked (and not ignored) files in your directory:
git ls-files --others --exclude-standard -z | xargs -0 tar rvf ~/backup-untracked.tar
如果要使用此技术,请仔细检查git ls-files --others --exclude-standard
本身是否会产生您期望的文件列表!
If you're going to use this technique, check carefully that git ls-files --others --exclude-standard
on its own produces the list of files you expect!
有关此解决方案的一些注意事项可能是有条理的:
A few notes on this solution might be in order:
-
我已经使用
-z
来获取git ls-files
,以NUL
(零字节)作为文件之间的分隔符来输出文件列表,并且xargs
的-0
参数告诉它认为NUL
是它从标准输入读取的参数之间的分隔符.这是处理文件名可能包含换行符的一种标准技巧,因为Linux上文件名中不允许的唯一两个字节是NUL
和/
.
I've used
-z
to getgit ls-files
to output the list of files withNUL
(a zero byte) as the separator between files, and the-0
parameter toxargs
tells it to considerNUL
to be the separator between the parameters it reads from standard input. This is a standard trick to deal with the possibility that a filename might contain a newline, since the only two bytes that aren't allowed in filenames on Linux areNUL
and/
.
如果您有大量未跟踪的文件,那么xargs
将多次运行tar
命令,因此,重要的是,我告诉tar
附加文件(r
)而不是而不是创建一个新的存档(c
),否则以后tar
的调用将覆盖之前创建的存档.
If you have a huge number of untracked files then xargs
will run the tar
command more than once, so it's important that I've told tar
to append files (r
) rather than create a new archive (c
), otherwise the later invocations of tar
will overwrite the archive created just before.
这篇关于如何快速备份要通过git clean删除的未跟踪文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!