1

In Gitlab/Github, if I use it remotely, I can download a file in a specific commit, by going to the commits and browser the repository at that commit.

If I use the Github desktop on windows with the repository on my PC (not push it to the remote), I tried to see a specific commit, I only find the difference of versions. But nowhere to see the entire file at that specific commit. Is there any method for doing it?

Redzeń
  • 13
  • 3
  • "Is there any method for doing it?" Yes, there is. (Well, I know how to do it from the command line. I don't use GitHub Desktop.) – matt Dec 30 '21 at 06:35
  • Tell me please, as long as it is locally ^_^ – Redzeń Dec 30 '21 at 06:42
  • You would say `git show commit:filepath`. – matt Dec 30 '21 at 06:49
  • I had a commit, name "2nd" and a file `1.txt`. I tried `git show 2nd:/mnt/c/Users/user/Documents/GitHub/test-a/test-a/1.txt`, got `fatal: invalid object name 'commit'` :( I may omit `1.txt`, same result – Redzeń Dec 30 '21 at 06:58
  • Your commit is not named `2nd`. A commit message is not a name. Its name is more like `ae93b60d`. – matt Dec 30 '21 at 07:00
  • Thanks. I found `e39...` on Github Desktop, and I used `git show e39...:/mnt/c/Users/user/Documents/GitHub/test-b/test-b/1.txt`, got `fatal: path '/mnt/c/Users/user/Documents/GitHub/test-b/test-b/1.txt' exists on disk, but not in 'e39...'` – Redzeń Dec 30 '21 at 07:05
  • Well now your path is wrong. – matt Dec 30 '21 at 07:14

1 Answers1

1

This is followed by desktop/desktop issue 6535 (for binary file, or any other type actually)

From 2019:

The biggest problem here is that while we can easily display the diff of changes in a repository, opening a specific version of a file is not easy - either we'd need to checkout that commit so the working directory has that version, or we extract the specific version of the file to a temporary location, which the default program can then open.

Here's a rough flow I can think of that might achieve this:

  • In "History" view, find a commit with an older version of the file you're interested in opening
  • When the user clicks to perform the action, Desktop will extract the blob from the repository to the OS temporary directory, using a pattern like {SHA}-{filename} so that we can avoid clashes if the user looks at multiple versions of a file
  • Once that file exists on disk, perform the existing behaviour of opening this new file in the default program

In command-line, you could use git show REVISION:path/to/file or git cat-file -p <sha1>:./file.tex > wherever.tex.

In your case:

cd /mnt/c/Users/user/Documents/GitHub/test-b
git show e39...:test-b/1.txt

Meaning: the path in git show should be the one from the root folder of the repository, not the OS full path.

The OP Redzeń confirms in the comments:

cd  test-b, 
# pwd: /mnt/c/Users/user/Documents/GitHub/test-b/test-b
git show e39...:1.txt
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. I tried to cd to the root folder of the repository, and `git show e39...:test-b/1.txt` and got `fatal: path 'test-b/1.txt' does not exist in 'e39...'` – Redzeń Dec 30 '21 at 07:20
  • I just tried to `cd test-b`, now I am at `/mnt/c/Users/user/Documents/GitHub/test-b/test-b`, and `git show e39...:1.txt`, it works!! – Redzeń Dec 30 '21 at 07:24
  • @Redzeń Well done! I have included your comment in the answer for more visibility. – VonC Dec 30 '21 at 07:26