Re: Extracting a file
- From
Jeff King <peff@peff.net>
- Date
- Jul 23, 2021, 07:01 UTC
- Message-ID
- <YPppNYOO26xAq2fn@coredump.intra.peff.net>
- In-Reply-To
- <CAB9Jk9DqCR8C9qx6-gZmpTQfBAKnEupQTb1WkJgN3YOqSO0=2A@mail.gmail.com>
On Thu, Jul 22, 2021 at 11:46:01AM +0200, Angelo Borsotti wrote:
Show 22 quoted lines
> 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