Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between staging and caching?

Tags:

git

I'm reading the book Pro Git, second edition.

It says, on page 21:

git diff --staged This command compares your staged changes to your last commit.

and a page later (without explaining what cached means)

git diff --cached to see what you've staged so far.

and now I'm a bit lost. What is the difference between staging and caching?

like image 279
Ortomala Lokni Avatar asked Jun 29 '15 20:06

Ortomala Lokni


People also ask

Whats is cache?

In computing, a cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data's primary storage location.

What is caching and types of caching?

Caching is a mechanism to improve the performance of any type of application. Technically, caching is the process of storing and accessing data from a cache. But wait, what is a cache? A cache is a software or hardware component aimed at storing data so that future requests for the same data can be served faster.

What is caching in architecture?

Caches reduce latency and service-to-service communication of microservice architectures. A cache is a high-speed data storage layer that stores a subset of data.

When should you not use cache?

Three caching challenges to consider Caches take up space on the disk, so we have to assess whether the time we are saving is worth the amount of disk space used. Cached data might not be the most accurate, particularly for volatile real-time data. Therefore, volatile data should not be cached.


2 Answers

They are synonymous; from the Git docs:

This form is to view the changes you staged for the next commit relative to the named . Typically you would want comparison with the latest commit, so if you do not give , it defaults to HEAD. If HEAD does not exist (e.g. unborn branches) and is not given, it shows all staged changes. --staged is a synonym of --cached.

like image 179
David Deutsch Avatar answered Oct 01 '22 20:10

David Deutsch


The “staging area”, or “cache” are both synonyms for the same thing which has another name in most other contexts in Git: The index.

The index is the area where changes are staged when you add them using git add (or git rm). It’s the set of changes that is committed when you do git commit.

All three names are usually used synonymously, although “cache” is rarely used outside of the --cached parameter in git diff.

like image 41
poke Avatar answered Oct 01 '22 18:10

poke