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

Checkout to different directory at certain commit without changing index

From
Ondra Medek <xmedeko@gmail.com>
Date
May 13, 2024, 07:26 UTC
Message-ID
<CAJsoDaEJn1Y0CgtxpkGqVRsTiDnMxjNFrtbTuUVOvT87N23JNg@mail.gmail.com>

Hello, I need a simple script for unskilled users to do a fast checkout (LFS friendly) of the current local Git clone at a certain commit to a different directory I.e. something like "copy at a point in history". IMO all possible solutions are summarized in this thread https://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export I describe some of them with my remarks:

- git checkout-index : works with HEAD only.
- git archive: influenced by export-ignore and export-subst
attributes, so may not produce exact copy of sources. (And needs tar).
- git worktree add -d : needs cleanup: git prune or git remove.
- git clone: Unfortunately, -b param cannot work with commit hash and
does not respect local worktree settings (e.g. autocrlf). So, a
solution may be a bit complicated: git clone -s -n . dest/path ; cp
.git/config dest/path/.git ; cd dest/path ; git co -q <commit-ish> ;
rm -rf .git
- git checkout: Unfortunately, modifies Git index, so some action to
revert index is necessary after: git --work-tree=/path/to/checkout/
checkout -f -q <tree-ish> -- ./

For me, the best solution is with git clone, because it does not modify Git index nor any source working tree settings, so no cleanup is necessary. But it's a bit complicated, though. It seems to me that "git checkout" could do this better and simpler if it would have some param to not modify the Git index. Is it possible to enhance git checkout? Or is there any other simple solution not mentioned in the SO thread?

Thank you Ondra Medek

Next: Phillip Wood
Message 1 of 7 in “Checkout to different directory at certain commit without changing index”
  1. Ondra MedekMay 13, 2024
  2. Phillip WoodMay 13, 2024
  3. Ondra MedekMay 13, 2024
  4. Ondra MedekMay 14, 2024
  5. phillip.wood123@gmail.comMay 14, 2024
  6. Ondra MedekMay 15, 2024
  7. phillip.wood123@gmail.comMay 14, 2024

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.