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

Checkout file without changing index?

From
Piotr Krukowiecki <piotr.krukowiecki@gmail.com>
Date
Apr 24, 2019, 13:37 UTC
Message-ID
<CAA01CsoJZMJ86mpybukqT0hVnvXi0FuRjZ23akM5kNPBdT754Q@mail.gmail.com>
Hi,
what is the standard/recommended way for updating a file to given version?
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.

After searching a bit I found "git show revision:file > file". But
it's problematic:
1. works only for 1 file. "git show revision -- file" does something else
2. requires full path, so you need to specify "git show
revision:relative/to/top/dir/file"

If there's no other easy way, maybe we could add "--no-index" to checkout: "git checkout --no-index revision -- file" (or similar - maybe use options from git-reset).

My use case: I had some changes prepared in index and wanted to compare the prepared version with some older version. The file was a zip file plus we use LFS so there was no other way than to "checkout" the file, unpack it and diff it.

-- 
Piotr Krukowiecki
Next: Junio C Hamano
Message 1 of 6 in “Checkout file without changing index?”
  1. Piotr KrukowieckiApr 24, 2019
  2. Junio C HamanoApr 24, 2019
  3. Piotr KrukowieckiApr 24, 2019
  4. Philip OakleyApr 24, 2019
  5. Sitaram ChamartyApr 25, 2019
  6. Junio C HamanoApr 25, 2019

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.