4

I want to version control my home directory in git.

I've used ncdu to find the largest sub-directories and from there built a .gitignore which I hope excludes the largest and most useless parts of my home directory (eg .gem/, .cache/, .cabal/, tmp/).

After doing a git add $HOME, how can I browse the index / cache / staging area with respect to disk usage?

Ideally, I'm after something interactive like ncdu where I can drill down into sub-directories.

Tom Hale
  • 40,825
  • 36
  • 187
  • 242
  • Are you interested in the size of the repository, or are you asking for the staging area (aka "index") specifically? Or the size of the changes size the last commit? – j6t Nov 26 '16 at 08:12
  • Size of the index. Imagine I've just done `git init; git add $HOME` and I want to have a `ncdu`-like look at what's in the index / cache / staging area. – Tom Hale Nov 26 '16 at 09:02
  • If you are going to do this, be especially sure to exclude directories like `.ssh`, or be meticulous on your permissions... or check out `etckeeper` which can be told to manage `$HOME` instead. Also, don't push to anywhere you wouldn't trust with your `ssh` keys! – Tom Hale Nov 26 '16 at 09:34
  • The index itself is a cache of `stat` data plus some Git-specific data including the hash ID of each "blob" that is now already added to the repository. You can examine the sizes of the objects, but even that may not be terribly useful since you won't know for sure how many times the object is shared, nor how the object will shrink once packed. – torek Nov 26 '16 at 13:12

2 Answers2

1

Stash data store in git-dir.

Default the git store data in folder .git (git-dir).

The latest stash you created is stored in refs/stash; older stashes are found in the reflog of this reference and can be named using the usual reflog syntax (e.g. stash@{0} is the most recently created stash, stash@{1} is the one before it, stash@{2.hours.ago} is also possible).

Grzesiek
  • 715
  • 5
  • 24
  • Won't this be a bunch of sha checksums in a new `.git` location? How would I browse this as a directory tree? – Tom Hale Nov 26 '16 at 09:04
0

The size of the index itself won't be relevant, since I detail in "What does the git index contain EXACTLY?":

The state is "virtual" in the sense that it does not necessarily have to, and often does not, match the files in the working tree.

What you can do is... make a commit (you can always git reset @~ to cancel the commit and redo it later)

Then, as mentioned in "git find fat commit":

git diff-tree -r -c -M -C --no-commit-id @     # get new blobs for HEAD commit
git cat-file --batch-check << blob ids         # get size of each blob

That will use git cat-file bach output to print information about them, including objectsize:disk.
If no format is specified, the default format is %(objectname) %(objecttype) %(objectsize).

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