Home > Software design >  How to restore files from previous commit?
How to restore files from previous commit?

Time:01-12

I find my commit where I deleted 10 files. After that, I committed a couple of times. NOw I only want to get these 10 files back on my branch

git log --diff-filter=D --summary 

shows

    Deleted 10 TIP files

 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/INT/api-service TIP [Common]/INT_COMMON.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/INT/api-service TIP [Xamarin]/INT_XAMARIN_ANDROID.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/INT/api-service TIP [Xamarin]/INT_XAMARIN_IOS.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/INT/api-service TIP [iOS]/INT_IOS_BitBucket.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/INT/api-service TIP [iOS]/INT_IOS_GitHub.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/PROD/api-service TIP [Common]/PROD_COMMON.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/PROD/api-service TIP [Xamarin]/PROD_XAMARIN_ANDROID.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/PROD/api-service TIP [Xamarin]/PROD_XAMARIN_IOS.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/PROD/api-service TIP [iOS]/INT_IOS_BitBucket.json
 delete mode 100644 test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/PROD/api-service TIP [iOS]/INT_IOS_GitHub.json

I tried

git checkout 525afffc8641671f9fe2c33b68dc211ed20d0ec8 -- "test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/INT/api-service TIP [Common]/INT_COMMON.json"

but got error with path

error: pathspec 'test-runner/src/v2/Avalanche.TestRunner.BuildsScenarios/Configuration/INT/api-service' did not match any file(s) known to git

If I go for

    git checkout 525afffc8641671f9fe2c33b68dc211ed20d0ec8
HEAD is now at 525afffc864 Deleted 10 TIP files

What next?

How to fix this?

CodePudding user response:

It looks like 525afffc86... is the commit where you deleted the files.

If such is the case, the files do not exist in that commit, which is why you get the did not match any file(s) known to git error, they exist in the parent commit :

# <commit-ish>^ points to the parent of target commit :
git checkout 525afffc^ -- "test-runner/src/v2/ ... /INT_COMMON.json"
  •  Tags:  
  • Related