Home > Back-end >  How to restore files recursively to a specific commit?
How to restore files recursively to a specific commit?

Time:12-07

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.

CodePudding user response:

Wildcards will work:

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

CodePudding user response:

If you are able to come up with a way to select your files, you can checkout only those files.

git checkout some-commit -- '*.c' '*.h'

I am using the quotes to keep bash from expanding them.

Also, sometimes things outside of git can give you a little hand:

git ls-tree --name-only -r some-revision | grep some-file-name-filter | xargs git checkout some-revision -- 
  • Related