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

Re: Extracting a file

From
ABAngelo Borsotti <angelo.borsotti@gmail.com>
Date
Jul 23, 2021, 07:38 UTC
Message-ID
<CAB9Jk9Af-GKFUQCiyN9fKmjA1hOLBw9mc_FPFBHX1m1NAnbfmQ@mail.gmail.com>
In-Reply-To
<YPppNYOO26xAq2fn@coredump.intra.peff.net>
Hi,
> You might also like "git checkout -p HASH -- A", which will let you pick
> individual hunks from HASH:A and apply them to your working tree.

This shows the differences between the committed and the current file, in a patch form, which is handy to apply to the current file to make it equal to the old, but not if I want to browse the old file and understand how it was before. Moreover, the command ends by asking:

    Apply deletion to index and worktree [y,n,q,a,d,?]?

and when I must be very careful to provide the correct answer so as not to damage my files. So many alternatives to simply get a file from the repo, some of which potentially dangerous, show that there is a need for a simple, safe command to get it.

-Angelo
On Fri, 23 Jul 2021 at 09:01, Jeff King <peff@peff.net> wrote:
Show 30 quoted lines
>
> On Thu, Jul 22, 2021 at 11:46:01AM +0200, Angelo Borsotti wrote:
>
> > Actually, I did not want to make git behave like a read-only filesystem,
> > but only to be able to get what is stored in it using some easy to remember
> > command.
> >
> > I guess that:
> >
> >     git mv A B &&
> >     git checkout HEAD -- A
> >
> > renames file A in the work, current, directory to B, and then recovers
> > A from the
> > repository. This changes the file on which I am working. After having
> > read the old
> > A, and understood what changes I make that are not correct, I should delete A,
> > and rename B back to A.
> > If something gets wrong with this, I risk to damage my original A.
> > This is why it is
> > better not to change it, and instead get a copy of the old one with
> > another name,
> > which is what
> >
> > git show HASH:file/path/name.ext > some_new_name.ext
>
> You might also like "git checkout -p HASH -- A", which will let you pick
> individual hunks from HASH:A and apply them to your working tree.
>
> -Peff
Previous: Jeff KingNext: Junio C Hamano
Message 5 of 8 in “Extracting a file”
  1. Angelo BorsottiJul 22, 2021
  2. Ævar Arnfjörð BjarmasonJul 22, 2021
  3. Angelo BorsottiJul 22, 2021
  4. Jeff KingJul 23, 2021
  5. Angelo BorsottiJul 23, 2021
  6. Junio C HamanoJul 23, 2021
  7. Junio C HamanoJul 23, 2021
  8. Felipe ContrerasJul 23, 2021

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.