Git - File


File management in Git (blob and not directory)

Note that a file for git is an blob object that may be:



See Git - File Status and short status


A file (or blob) identifier is the hash of its content.


To see the content, with the show command and its hash

git show thehash

Commit History for one File

git log --all --full-history -- **/thefile.*

Git - Log (Commit History)


git-ls-files 1) - Show information about files in the index and the working tree

Show a file for a commit


git show commitHash:path/to/file

Restore it

The caret symbol (^) gets the checkout prior to the one identified

git checkout <SHA>^ -- <path-to-file>

What is a Git Checkout?

  • Update the requested file from the given branch (here the remote branch origin/master).
git checkout remote/branch fileName
# Example
git checkout origin/master fileName

Rename or move a file

git mv <options>…​ <args>…​
git mv oldName.ext newName.ext

This is not rename tracking.

Its just an utility class that remove a file and add another one with the same content because Git don't track rename

Remove it

  • from the repository (index) but not from the file system
git rm --cached myFileName.extension

more Git - rm (Remove)


With log, you can see the commit history and the hash.

The –follow will list the history of a file beyond renames (it searches for similar content using heuristics).

Example for one file:

git log --follow --oneline -- MyFile
# or for full sha1
git log --follow --pretty=oneline -- MyFile
3af5d4a Backup Snapshot
4240d72 Commit message
9dc93b5 Backup - Child of a slot implementation
4cadd4f Release 1.24
c343705 Release 1.22
1fa8c41 Release 1.21

  • With the gitk, you got it visually
gitk --follow MyFile

Discover More
Git - Blob

blob in git is a object of the blob type that corresponds / represents the file contents (or inodes) in the git file system. file This command will put a blob in the object database where: the...
Git Commit Tree Data Model
Git - Commit

A commit in git is an object that stores the information : who saved the file system snapshots, when they were saved, why they were saved. the commiter the author the parent commit It's...
Git - File

File management in Git (blob and not directory) blob object on the local file system or not (ie in the git file system database) See and short status A file (or blob) identifier is the...
Git File Lifecycle
Git - File Status

The status of a file in a working directory is one of: where: State Tracked Description untracked New file unmodified Tracked File is the same as in the last commit modified Tracked File...
Git - Objects (Database)

An object is the value in the entry of the git database key-value. All entities in git are objects. Objects are the entity of the Git file system. On the operating file system, the objects are stored...
Git - Show

git show is a general command line tool that shows information object where hash is the object hash for commits it shows the log message and textual diff. It also presents the merge commit in a...
Git File System
What is the Git File System ?

git has a file system application feature. The whole git file system is stored in the object database where: the tree objects corresponds to UNIX directory entries (ie directory) and blob objects...

Share this page:
Follow us:
Task Runner