Skip to main content
Active reading [<https://en.wikipedia.org/wiki/One-liner_program>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

In our case we accidentally deleted files in a commit and some commitcommits later we realized our mistake and wanted to get back all the files that were deleted, but not those that were modified.

Based on Charles Bailey's excellent answer, here is my one liner-liner:

git co $(git rev-list -n 1 HEAD -- <file_path>)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- <file_path>)~1 head | grep '^D' | cut -f 2)

In our case we accidentally deleted files in a commit and some commit later we realized our mistake and wanted to get back all the files that were deleted but not those that were modified.

Based on Charles Bailey's excellent answer here is my one liner:

git co $(git rev-list -n 1 HEAD -- <file_path>)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- <file_path>)~1 head | grep '^D' | cut -f 2)

In our case we accidentally deleted files in a commit and some commits later we realized our mistake and wanted to get back all the files that were deleted, but not those that were modified.

Based on Charles Bailey's excellent answer, here is my one-liner:

git co $(git rev-list -n 1 HEAD -- <file_path>)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- <file_path>)~1 head | grep '^D' | cut -f 2)
Source Link
bonyiii
  • 2.9k
  • 31
  • 26

In our case we accidentally deleted files in a commit and some commit later we realized our mistake and wanted to get back all the files that were deleted but not those that were modified.

Based on Charles Bailey's excellent answer here is my one liner:

git co $(git rev-list -n 1 HEAD -- <file_path>)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- <file_path>)~1 head | grep '^D' | cut -f 2)