Git - File (Blob)


File management in Git (blob and not directory)

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




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>

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

Powered by ComboStrap