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

fatal: bad revision '$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''

我该如何解决这个问题?

如果您在 CMD 中使用 Windows,那么是的,因为 by Marc 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
...