Git中是否有可能将文件从索引中删除?

发布于 2025-01-18 17:08:40 字数 368 浏览 3 评论 0原文

我想做:

git rm --cached file.autogenerated.txt
git stash -m "untrack file.autogenerated.txt"

创建藏匿处,但似乎在藏匿处没有任何东西 - 只有0个文件更改,0插入,0删除。应用此藏匿没有任何效果。

我也尝试过:

git rm --cached file.autogenerated.txt
git stash --include-untracked -m "untrack file.autogenerated.txt"

但同样,这也没有效果。

有什么办法可以将索引中的文件删除?

I want to do:

git rm --cached file.autogenerated.txt
git stash -m "untrack file.autogenerated.txt"

The stash is created but it doesn't seem to have anything in the stash - just 0 files changes, 0 insertions, 0 deletions. And applying this stash has no effect.

I also tried:

git rm --cached file.autogenerated.txt
git stash --include-untracked -m "untrack file.autogenerated.txt"

But likewise this had no effect.

Is there any way to stash a removal of a file from the index?

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

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

发布评论

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

评论(1

2025-01-25 17:08:40

您可以使用 git stash pop --index 重新应用删除,例如

$ git add foo bar
$ git commit -m 'initial'
[master (root-commit) 4bf33f4] initial
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
 create mode 100644 foo
$ git rm --cached bar
rm 'bar'
$ git stash
Saved working directory and index state WIP on master: 4bf33f4 initial
$ git status
On branch master
nothing to commit, working tree clean
$ git stash pop --index
Already up to date.
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    deleted:    bar

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    bar

Dropped refs/stash@{0} (a998ca45e1230d40ac84403c9d84b5328e89b5bf)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    deleted:    bar

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    bar

You can re-apply the deletion using git stash pop --index, e.g.

$ git add foo bar
$ git commit -m 'initial'
[master (root-commit) 4bf33f4] initial
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
 create mode 100644 foo
$ git rm --cached bar
rm 'bar'
$ git stash
Saved working directory and index state WIP on master: 4bf33f4 initial
$ git status
On branch master
nothing to commit, working tree clean
$ git stash pop --index
Already up to date.
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    deleted:    bar

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    bar

Dropped refs/stash@{0} (a998ca45e1230d40ac84403c9d84b5328e89b5bf)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    deleted:    bar

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    bar
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文