在没有索引更改的情况下从存储中弹出

Pop from stash without indexing changes

上下文:

我想在 git 预提交挂钩中 运行 rubocop,但我假设我有一个隐藏的更改会导致它抱怨,以及一个未隐藏的更改以某种方式解决这个问题,令人反感的变化会被 rubocop 忽略。

目前我的解决方案:

在 运行ning rubocop 之前,运行 git stash --keep-index -u 在 运行ning rubocop

之前存储所有未暂存的更改

问题:

在 运行ning rubocop 之后,git stash pop 将工作树恢复到之前的状态,但会暂存所有这些更改(之前未暂存)

我的问题:

是否可以选择弹出存储而不自动暂存任何弹出的更改?

是否有其他方法 运行 项目中的程序将被提交,而不是具有可能未暂存更改的工作树?


重现情况:

# Set up a dummy repo
  git init
  echo foo > file
  git add foo && git commit -m "Initial"
# Make a change and stage it
  echo bar >> file
  git add file
# Make another change and *don't* stage it
  echo baz >> file
# This is what I later want to restore:
  git status && git diff && git diff --cached
# Stash only unstaged changes (and ignored / untracked files)
  git stash --keep-index -u
# So far everything is as it should be
  git status && git diff && git diff --cached
# Run whatever script on the code
  rubocop .
# This is where things go wrong though:
  git stash pop
# Both changes are now staged to be committed 
  git status && git diff && git diff --cached

Is there an option to pop the stash without automatically staging any of the popped changes?

不是一个选项,不,但是你可以通过

自己获得那种效果
index=`git write-tree`
git stash pop
git read-tree $index