致命:错误的修订版 '$GIT_COMMIT''

问题描述

我只想查看每次提交时 GIT_COMMIT 变量的内容

git filter-branch --tree-filter 'echo $GIT_COMMIT' -- --all

我收到此错误

WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort,then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/neWren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

fatal: bad revision '$GIT_COMMIT''

我应该如何解决这个问题?

解决方法

如果您在 Windows 上使用 CMD,那么是的,如 commentedMarc Luzzara,使用双引号有帮助。

但实际的错误消息,在 CMD shell 中带有单引号,将是:

set FILTER_BRANCH_SQUELCH_WARNING=1

git filter-branch --tree-filter 'echo $GIT_COMMIT' @

fatal: ambiguous argument '$GIT_COMMIT'': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions,like this:
'git <command> [<revision>...] -- [<file>...]'


# or,as mentioned in the OP

git filter-branch --tree-filter 'echo $GIT_COMMIT' -- --all
fatal: bad revision '$GIT_COMMIT''

相同的命令在 git bash 会话中起作用:

$ git filter-branch --tree-filter 'echo $GIT_COMMIT' -- --all
Rewrite 92a741579ad31e6ccb17fda876e084b181bbdcdb (1/4) (0 seconds passed,remaining 0 predicted)    92a741579ad31e6ccb17fda876e084b181bbdcdb
...