2

I know that you can restore a previously removed directory as follows

git checkout {revision} -- {dir}

However, the history of all files in the restored directory is completely gone. They are all seen as 'new' files.

Is there a way to restore the directory while still preserving its files' history?

dstibbe
  • 1,589
  • 18
  • 33
  • You have to clarify what you want... Do you want to explore history, and then come back to your branch tip? Discard completely recent history as if it never existed? Keep the history, but add a new commit that restores an old state? – Matthieu Moy May 15 '15 at 08:01

1 Answers1

1
git tag originalHead # just in case
git rebase -i <id of the parent of the commit that deleted the file>
# change pick to edit for that commit
git checkout <id of the previous commit> <filename>
git commit --amend
git rebase --continue
git tag -d originalHead

I found this here

Community
  • 1
  • 1
Joost
  • 3,169
  • 2
  • 22
  • 40