Search code examples
windowsgitgit-filter-branch

fatal: bad revision '$GIT_COMMIT''


I just want to see the content of GIT_COMMIT variable over each commit:

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

I get this error:

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''

How should I fix this?


Solution

  • If you are on Windows in a CMD, then yes, as commented by Marc Luzzara, using double-quotes helps.

    But the actual error message, with single quotes in a CMD shell, would be:

    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''
    

    The same command works in a git bash session:

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