Search code examples
windowsgitversion-control

How to restore files recursively to a specific commit?


I need to restore all app.config files in my repository to a specific commit, regardless on where those files reside. I know, that git checkout allows restoring a file or a folder to a specific commit, but is there a way to do that recursively without picking all files or using scripts?

I tried:

$ git checkout <commit> -- App.config

error: pathspec 'App.config' did not match any file(s) known to git

$ git checkout <commit> -- */App.config
error: pathspec '(Folder 1)/App.config' did not match any file(s) known to git
error: pathspec '(Folder 2)/App.config' did not match any file(s) known to git
error: pathspec '(Folder 3)/App.config' did not match any file(s) known to git
error: pathspec '(Folder 4)/App.config' did not match any file(s) known to git
...

Those files actually are known to git, because if I go inside the folder and do:

git checkout <commit> -- ./App.config

It works, but only for this single file.


Solution

  • Wildcards will work:

    git checkout abc123 -- '**/app.config'