Re: Retrieving a file in git that was deleted and committed
- From
- biswaranjan panda <biswaranjan.nitrkl@gmail.com>
- Date
- Dec 7, 2018, 07:07 UTC
- Message-ID
- <CADHAf1Y8or_frf=Ecu-82z-jo06NKe7oqo1cxtsZsOxhKKxjAw@mail.gmail.com>
- In-Reply-To
- <CAGyf7-FUHMEq_FfPNrH6uT2b-nCd_wi=Aww+OUuoDem11DROGA@mail.gmail.com>
Thanks! Strangely git log --follow does work. On Thu, Dec 6, 2018 at 10:55 PM Bryan Turner <bturner@atlassian.com> wrote:
Show 32 quoted lines
> > On Thu, Dec 6, 2018 at 10:49 PM biswaranjan panda > <biswaranjan.nitrkl@gmail.com> wrote: > > > > 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 > > It doesn't change anything, but note that you don't need to checkout B > first, to restore the file. If you know a commit SHA where the file is > present, "git checkout SHA -- path_to_file" will pull back the file as > it existed at that commit. > > > > > 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 > > It's not possible, as far as I'm aware. While the new file has the > same name as the old file, to Git they are two unrelated entries that > happen to reside at the same path. Even things like "git log --follow" > won't consider the file to be related to its previous history. > > Bryan
-- Thanks, -Biswa