Extracting previous copy from github [til/cli]

Sometimes I need to pull a complete copy of a previous file out of a github (this is useful when needing to do visual binary diffs to see which bytes have moves or changed).
To pull a specific file, say the last commit, the following command line does the trick:
git show HEAD^:./myfile.bin > myfile.bin

The HEAD^ means “one commit behind the head of the branch” (the “head” being the last commit on the branch). Though if you’ve got merge commits where a commit has more than one parent commit this can get a little complicated (which why I tend to stick to just the previous commit).
Using HEAD^^ or HEAD^2 means “two commits before the head of the branch”. There’s also detailed stackoverflow post about the difference between the caret ^ and the tilde ~ with examples of how they traverse up the tree.


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log

Sometimes I need to pull a complete copy of a previous file out of a github (this is useful when needing to do visual binary diffs to see which bytes have moves or changed).

To pull a specific file, say the last commit, the following command line does the trick:

git show HEAD^:./myfile.bin > myfile.bin

The HEAD^ means "one commit behind the head of the branch" (the "head" being the last commit on the branch). Though if you've got merge commits where a commit has more than one parent commit this can get a little complicated (which why I tend to stick to just the previous commit).

Using HEAD^^ or HEAD^2 means "two commits before the head of the branch". There's also detailed stackoverflow post about the difference between the caret ^ and the tilde ~ with examples of how they traverse up the tree.

Originally published on Remy Sharp's b:log


This content originally appeared on remy sharp's b:log and was authored by remy sharp's b:log


Print Share Comment Cite Upload Translate Updates
APA

remy sharp's b:log | Sciencx (2021-07-02T09:51:37+00:00) Extracting previous copy from github [til/cli]. Retrieved from https://www.scien.cx/2021/07/02/extracting-previous-copy-from-github-til-cli/

MLA
" » Extracting previous copy from github [til/cli]." remy sharp's b:log | Sciencx - Friday July 2, 2021, https://www.scien.cx/2021/07/02/extracting-previous-copy-from-github-til-cli/
HARVARD
remy sharp's b:log | Sciencx Friday July 2, 2021 » Extracting previous copy from github [til/cli]., viewed ,<https://www.scien.cx/2021/07/02/extracting-previous-copy-from-github-til-cli/>
VANCOUVER
remy sharp's b:log | Sciencx - » Extracting previous copy from github [til/cli]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/02/extracting-previous-copy-from-github-til-cli/
CHICAGO
" » Extracting previous copy from github [til/cli]." remy sharp's b:log | Sciencx - Accessed . https://www.scien.cx/2021/07/02/extracting-previous-copy-from-github-til-cli/
IEEE
" » Extracting previous copy from github [til/cli]." remy sharp's b:log | Sciencx [Online]. Available: https://www.scien.cx/2021/07/02/extracting-previous-copy-from-github-til-cli/. [Accessed: ]
rf:citation
» Extracting previous copy from github [til/cli] | remy sharp's b:log | Sciencx | https://www.scien.cx/2021/07/02/extracting-previous-copy-from-github-til-cli/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.