Re: Checkout file without changing index?
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 24, 2019, 13:46 UTC
- Message-ID
- <xmqq5zr31poo.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <CAA01CsoJZMJ86mpybukqT0hVnvXi0FuRjZ23akM5kNPBdT754Q@mail.gmail.com>
Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
Show 5 quoted lines
> I was familiar with "git checkout revision -- file". > > But it updates both working tree and index. I had some changes in > index (staged) and "git checkout HEAD -- file" silently overwritten > it. Well, probably my mistake, it's documented.
We'd invite you to live on the leading edge and try
$ git restore --source=<revision> <pathspec>
which by default checks things out only to the working tree, but not to the index (you say --staged if you want to restore to the index, and you say --worktree if you want to restore to the working tree, or you can say both, which would be the same as "git checkout").
I think the new command is now on the 'pu' branch, but in a few weeks hopefully it will appear on the 'next' branch.