1

I have a git repository, and its log history is shown below.

../mypapers/Doc_thesis$ git log 
commit 5bbb3681e1630a423f143a2e97350f463669c214
Author: ShijieXu <shijiexu@yahoo.com>
Date:   Wed Nov 16 14:10:16 2016 -0400

    Revist GraphJIT

commit e8ccd771208c5d328936422d60dcae2d3850e3a1
Author: ShijieXu <shijiexu@yahoo.com>
Date:   Tue Nov 8 15:04:22 2016 -0400

    version

commit c8f2313c324cd0a07e67eb07f060d319bb4faa69
Author: ShijieXu <shijiexu@yahoo.com>
Date:   Wed Apr 13 11:03:53 2016 -0300

    another chapter

My questions are:

  1. How to check a file's current version? For example, I normally switch file version using git checkout c8f2313c324cd0a07e67eb07f060d319bb4faa69, so after several revision changes, is there any way to check out which revision the current file is?
  2. How to handle some deleted files when changing the commit number. For example, The commit e8ccd771208c5d328936422d60dcae2d3850e3a1 contains deleting a number of files. After checking out to this commit and then back to the 5bbb3681e1630a423f143a2e97350f463669c214, git status will show up some new files, which have all been removed.

    git status 
    On branch final_thesis
    Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)
    new file:   #introduction.tex#
    new file:   UNBThesis2-1101.tex
    new file:   UNBThesis2_0430.pdf
    new file:   UNBThesis2_bak.tex
    

Thanks

Zoe
  • 27,060
  • 21
  • 118
  • 148
shijie xu
  • 1,975
  • 21
  • 52
  • If you're on Linux, install `gitg` - it'll give you a visual representation of what's going on which I think will help a lot. – bcmcfc Nov 16 '16 at 19:17
  • Are you really particularly interested in a *file* version, or do you care more about a *commit* version? Your example, of `git checkout `, selects a particular *commit*, which represents potentially many files. – torek Nov 16 '16 at 20:22

1 Answers1

2
  1. It depends on how you checkout your older version of files:

    • git checkout SHA1: your index is in a detached HEAD mode (you are no longer in abranch). git diff yourBranch should show you the difference between your detached HEAD and the branch.
    • git checkout SHA1 -- afile: you change just the content of one file
      git diff is enough in that case.
  2. If you don't have any work in progress, you can reset (hard) to your original SHA1:

    git reset --hard original_SHA1 
    

If the reset leaves untracked files behind, add a git clean -fdx.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250