简体   繁体   English

忽略 git 状态中的旧未跟踪文件

[英]Ignore old untracked files in git status

This is a problem caused entirely by my own laziness.这完全是我自己的懒惰造成的问题。 In some projects I tend to accumulate a bunch of temporary files that I don't want to delete yet, but don't want to commit either.在某些项目中,我倾向于积累一堆我还不想删除但也不想提交的临时文件。 And because they are just my local temp files, I don't want to .gitignore them either.而且因为它们只是我的本地临时文件,所以我也不想.gitignore它们。

Is there a way to make git status only show untracked files if they have been modified in last X days?有没有办法让git status只显示未跟踪的文件,如果它们在过去 X 天内被修改过?

Here is the script I use now instead of git status :这是我现在使用的脚本,而不是git status

#!/bin/bash

OLD_THRESHOLD="+30" # More than 30 days old
OLD_UNTRACKED=$(git status --porcelain=2 | \
                grep '^[?] ' | cut -d' ' -f 2- | \
                xargs -I X find X -maxdepth 0 -mtime $OLD_THRESHOLD )

git -c color.status=always status | grep -vF "$OLD_UNTRACKED"

It takes a list of the untracked files, and filters out any that have mtime older than 30 days.它获取未跟踪文件的列表,并过滤掉任何mtime超过 30 天的文件。

Note that the untracked files will still cause you (me?) trouble in eg git add folder .请注意,未跟踪的文件仍会在例如git add folder中给您(我?)带来麻烦。 It is still better to organize directories so that temporary files are in an gitignored folder.最好组织目录,以便临时文件位于 gitignored 文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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