git:我可以隐藏未跟踪的文件而不将其添加到索引吗?

发布于 2024-09-10 09:45:10 字数 669 浏览 6 评论 0原文

一个相关的问题如何存储未跟踪的文件?是回答“跟踪文件”。然而,这不能满足我的特殊需求。

我正在尝试使用 git stash save --keep-index 来隐藏索引中没有的所有内容,以便我可以在预提交挂钩中验证索引。这个想法来自 git-stash 手册页的“测试部分提交”示例。我想确保我实际提交的内容通过了测试,而不仅仅是工作目录中的内容。到目前为止,这就是我所拥有的:

echo "Running tests on the staging area."
git stash save --keep-index
# configure, build, run tests, clean
git stash pop; true

这似乎一直有效,直到我的工作目录中存在未隐藏的未跟踪文件。一些搜索导致了两年前的功能请求:保存未跟踪的选项和/或忽略存储中的文件,但仅此而已。

我应该使用储藏室吗?也许有更好的方法涉及临时分支或其他东西。

A related question How do you stash an untracked file? was answered with "track the file." This doesn't work for my particular needs, however.

I'm trying to stash everything that isn't in the index with git stash save --keep-index so that I can validate the index in my pre-commit hook. The idea is from the "Testing partial commits" example of the git-stash man page. I want to make sure that what I'm actually committing passes the tests and not just whats in the working directory. Here's what I have so far:

echo "Running tests on the staging area."
git stash save --keep-index
# configure, build, run tests, clean
git stash pop; true

This seems to work until I have untracked files in my working directory which don't get stashed. Some searching resulted in a feature request from two years ago: Option to save untracked and/or ignored files in stash, but nothing else.

Should I be using stash at all? Perhaps theres a better way involving temporary branches or something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻安 2024-09-17 09:45:10

正如我回答相关问题时,答案现在是肯定的:

从 git 1.7.7 开始,git stash 接受 --include-untracked 选项以将未跟踪的文件包含在你的藏品。

git stash --include-untracked

或者您可以使用简短的 -u 选项。

git stash -u

As I answered on the related question, the answer is now YES:

As of git 1.7.7, git stash accepts the --include-untracked option to include untracked files in your stash.

git stash --include-untracked

Or you can use the short -u option.

git stash -u
尤怨 2024-09-17 09:45:10

不,git stash 只会“记录工作目录和索引的当前状态”。因此,隐藏不会拾取您未跟踪的文件。

正如您所建议的,切换到临时分支并跟踪那里未跟踪的文件似乎是一种合理的方法。

No, git stash will only "record the current state of the working directory and the index". So stashing won't pickup your untracked files.

Switching to a temporary branch and tracking the untracked files there, as you suggest, seems like a reasonable approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文