git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Retrieving a file in git that was deleted and committed

From
BPbiswaranjan panda <biswaranjan.nitrkl@gmail.com>
Date
Dec 7, 2018, 06:49 UTC
Message-ID
<CADHAf1Y_d=-9By4jC2xd+BmWJgfGmBNUr=uSuQtfuHDrarN4kw@mail.gmail.com>
I have the following scenario:

On a branch A, I deleted a file foo.txt and committed the change. Then I did a bunch of other changes. Now I want to undelete foo.txt.

One way is to checkout a separate branch B where the file is present. Then checkout A. Then do git checkout B -- path_to_file

While this does gets the file back, the file shows up as a new file to be committed. Once I commit it, git blame doesn't show the old history for the file.

I would appreciate if anyone knows how to preserve git blame history.
Next: Bryan Turner
Message 1 of 12 in “Retrieving a file in git that was deleted and committed”
  1. biswaranjan pandaDec 7, 2018
  2. Bryan TurnerDec 7, 2018
  3. biswaranjan pandaDec 7, 2018
  4. Jeff KingDec 7, 2018
  5. Bryan TurnerDec 7, 2018
  6. biswaranjan pandaDec 7, 2018
  7. Jeff KingDec 8, 2018
  8. biswaranjan pandaDec 9, 2018
  9. Junio C HamanoDec 11, 2018
  10. Elijah NewrenDec 10, 2018
  11. Jeff KingDec 11, 2018
  12. Sergey OrganovDec 10, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.