shijie xu
shijie xu

Reputation: 2097

Check git current file version and how to handle removed files

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

../mypapers/Doc_thesis$ git log 
commit 5bbb3681e1630a423f143a2e97350f463669c214
Author: ShijieXu <[email protected]>
Date:   Wed Nov 16 14:10:16 2016 -0400

    Revist GraphJIT

commit e8ccd771208c5d328936422d60dcae2d3850e3a1
Author: ShijieXu <[email protected]>
Date:   Tue Nov 8 15:04:22 2016 -0400

    version

commit c8f2313c324cd0a07e67eb07f060d319bb4faa69
Author: ShijieXu <[email protected]>
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

Upvotes: 1

Views: 248

Answers (1)

VonC
VonC

Reputation: 1326556

  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.

Upvotes: 2

Related Questions