Git - File


File management in Git.


Commit History for one File

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

Git - Log (Commit History)

Get the list of files in a commit

git show --pretty="" --name-only <SHA>
git diff-tree --no-commit-id --name-only -r <SHA>

Show a file for a commit

git show <SHA> -- <path-to-file>

Git - Show

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

Remove it

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

more Git - rm (Remove)

Powered by ComboStrap