Search code examples
bashgitgnome-terminal

How to pass wildcard string to git from bash / gnome terminal


This command works in git 2.30.0.windows.1 through the Windows 'command' shell.

git checkout [commit hash] -- */migrations/*

It doesn't work with Mate terminal or bash (git 2.17). The problem is that they substitute the present content of the directories */migrations/* (which are empty or don't have the files that were present at the commit I want to pull them from). Mate terminal does this whether I single or double quote.

If I invoke Bash and then, at the new command line, add single or double quotes, git says that it doesn't have any files literally called */migrations/*:

error: pathspec '*/migrations/*' did not match any files known to git

I can get the content of the migrations files if I substitute directories one at a time, but there are 20+ folders of migrations and I assume I have just missed a bit of lore about how to get what I want from a Linux terminal. Can anyone suggest what I ought to be doing?


Solution

  • This */migrations/* syntax is referring to nowhere path. Neither root nor current working directory.
    Try these with ls command before checkout with git:

    • *migrations/*
    • ./*migrations/*
    • $PWD/migrations/*

    And if you got the right output with ls then apply it to git checkout ...


    Test 1

    ls */tmp/*
    ls: cannot access '*/tmp/*': No such file or directory
    

    Test 2

     ls /tmp/*
     it has output ...
     it has output ...