0

I am using Doom Emacs 2.0.9 on Emacs 27.2.

I use magit to manage a local git repository.

In an earlier commit, there was a file. In the latest commit as well as the current working tree, the file no longer exists as it was deleted somewhere along the way.

I want to have that file from the earlier commit in the current working tree. How do I do that using magit?

deshmukh
  • 1,852
  • 13
  • 29
  • Related: https://emacs.stackexchange.com/questions/7655/how-can-i-open-a-specific-revision-of-a-file-with-magit – phils Jun 23 '21 at 05:07
  • 2
    Does this answer your question? [How do I checkout a file from another commit in Magit](https://emacs.stackexchange.com/questions/14463/how-do-i-checkout-a-file-from-another-commit-in-magit) – phils Jun 23 '21 at 05:13

2 Answers2

2

You can use magit-file-checkout on the commit hash of your interest, or find the command (most likely f file) in Reset menu.

After selecting the commit hash, choose the file you wanna resurrect.

TerryTsao
  • 1,176
  • 4
  • 18
0

First you have to find the revision where the file was deleted. You can do that with magit-log, then advice the full file name in "Limit to files". You will get the commit where the file was removed at the top of the log buffer.

You can open file as it was just before deleted with magit-find-file, settings revision to rev^ where rev is the commit that delete the file. Or checkout it (magit-file-checkout) at the revision rev^.

Balaïtous
  • 173
  • 7