LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 11-02-2018, 10:53 AM   #1
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Rep: Reputation: 13
Novice, git, recover previous version


Summary: There is a local git repository and I need to restore a file two or three versions back.

Details
My searches had discovered that: “git hist” will return a list of git commits. As you know that provides the author, date, and a very long number representing the file committed. I don’t know which file is represented by each number, or which version. The git commands I have found to actually fetch a previous version show a much shorter number for the actual process of fetching the version wanted. How do I get that number?

I did search and was not able to find a link to a site with what I needed. I am behind government firewalls and some sites were blocked, probably the best ones.

I was able to determine the answer. It is at the bottom of post # 5 of this thread, Edit 02

Still, a question remains. What command will show the file(s) saved with a given commit command?

Last edited by bkelly; 11-14-2018 at 10:16 AM.
 
Old 11-03-2018, 05:01 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
sorry to be the one to tell you, but putting your title in a search query returns many relevant-looking results, esp. this one.
 
Old 11-03-2018, 05:03 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you need to learn git. There are a lot of commands like:
Code:
git show <commit id>   # this will show you what was committed (changed in a given commit).
git log                # list of commits (like history)
git checkout <commit id> # this will "recover" any commit you have.
.....
The short and long commit ids are the same, just sometimes we use the full string, sometimes only the first 7 characters.

Git does not handle files, but the whole repository "in one". That means every commit id represents a state of the whole repository (workspace), not only a single file.

You could hopefully find a git tutorial or something on the net which is not blocked. There are man pages, youtube videos, pdf documentation and whatever you can imagine.
 
Old 11-03-2018, 05:43 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by bkelly View Post
I am behind government firewalls and some sites were blocked, probably the best ones.
oh, i missed that bit.
sorry if my reply was just a little snarkier than necessary.
i really hope you can use stackoverflow, the second link in my post.
 
Old 11-13-2018, 11:23 AM   #5
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Original Poster
Rep: Reputation: 13
ondoho,
Been on travel for a week and just returned. No problem with any snarkiness. For example, your git 1 link returns an error stating "Can't connect securely to this page" and the firewalls do not allow an insecure connection. It is even more difficult because my Linux box is completely isolated and I cannot copy paste to ask questions.

I am working on tutorials. When I get a log file listing, rather than a file name I can only get the SHA1 number. But that number means nothing to me. I am looking for a way to convert that number to a file name. Seems like someone would have written a script to read those log outputs and somehow fetch the actual names and present that to the user. That is my current plan of attack. I remain a Linux novice.

Edit:
from here: http://www.vogella.com/tutorials/Git...ommitreference
Section 28.1 is titled Retrieving file from the history. It has this example command:
Quote:
git show [reference]:[file_path]
I am unable to determine exactly what to insert in place of [reference]. The SHA number does not work and the file path/name is already there.

In my directory, with a local git repository, there is a file named: Walkthrough template.odt. The goal is to retrieve not the last committed version but the one before that. What steps will accomplish this goal?

Edit 02

After looking at an example that compressed multiple commands and responses one line with no explanation I have discovered this method. Begin with:
Code:
git log -–oneline
This provides a list of commits shown with one line per commit and shown as repeats of
Quote:
Reference_number commit_comments
There is one line for each commit and each has a unique reference number.
If the person doing the commit made good comments then you can select the commit to use. Then enter:
Code:
git   reference_number    file_name
Where reference number is the number at the beginning of one of the commit lines and the file name is simply the name of the file to be restored.
Several sites have that format, but don’t describe what that reference number is.
So, is this a valid method? It worked for my test directory but will it always work?

Still, a question remains. What command will show the file(s) saved with a given commit command?

Last edited by bkelly; 11-14-2018 at 10:16 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to reset, revert, and return to previous states in Git LXer Syndicated Linux News 0 06-19-2018 08:51 AM
LXer: Last Call for Purism's Librem 5 Dev Kits, Git Protocol Version 2 Released, LXQt Version 0.13.0 Now Available and More LXer Syndicated Linux News 0 05-23-2018 07:34 AM
LXer: How to recover from a git mistake LXer Syndicated Linux News 0 08-18-2017 08:51 AM
[SOLVED] git help: revert master to a previous snapshot sycamorex Linux - General 6 04-09-2015 05:22 PM
i lost my previous linux OS link-how do i recover jagdishpandey Linux - Kernel 8 07-18-2007 07:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 06:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration