TITLE: Exactness and obstruction in sheaf cohomology
QUESTION [9 upvotes]: Given a topological space $X$, sheaf cohomology 'measures' the lack of exactness of the global section functor $\Gamma(X, -) : \textbf{Sh}(X) \to \textbf{Ab}$.
From another viewpoint, sheaf cohomology should be measuring the 'obstruction to lifting local to global data'.
I understand the notion of a sheaf as a local assignment to a topological space of algebraic structures that compatibly 'restrict' and 'glue'; and the global sections functor that maps $\mathcal{F} \mapsto \mathcal{F}(X)$.
Yet, I don't understand the connection between the exactness of $\Gamma(X, -)$ and the capability to 'lift local data to global'.
How do these two viewpoints connect?

REPLY [3 votes]: As another viewpoint, I would propose considering Čech complexes of the sheaf. These give rise to a more refined version of the "local-to-global" principle in sheaves. This became way longer than I wanted, but it was fun to write anyway.
Intro
In a lot of practical cases, if you have a sheaf $S$ over a space which is "sufficiently small" or "looks sufficiently like $\mathbb{R}^n$", then the sheaf cohomology of $S$ vanishes in nonzero degree: Think about the cohomology of the constant sheaf, or the sheaf of holomorphic functions. We often understand this as "topologically, this space isn't very interesting".
The cohomology of these sheaves certainly doesn't vanish over every space, but we can often cover our topological spaces by "good" covers, where every element (and every intersection of elements) in the cover is an open set over which the sheaf cohomology becomes trivial -- well, the quotation marks aren't even necessary, people really call these covers "good covers" :) Very often, these good covers will consist of open sets where every participant (all the sets themselves, and all their intersections) is homeo-/diffeo-/biholomorphic to an open disk.
Mathematics
Let us make this precise: Let $M$ be a topological space, $S$ a sheaf on $M$ with values in the category of abelian groups, and $\mathcal{U}$ an open cover of $M$ so that the sheaf cohomology of $S$ vanishes when restricted to any intersection of elements in $\mathcal{U}$, so
$$H^i(S|_{U_{i_0} \cap \dots \cap U_{i_n}}) = 0 \quad \forall U_i \in \mathcal U, i \geq 1.$$
Then $\mathcal{U}$ is a Leray cover for the sheaf $S$, and by the Leray theorem, the sheaf cohomology of $S$ is isomorphic to the cohomology of the Čech complex associated to the open cover $\mathcal{U} = \{U_i\}_{i \in I}$, which has the shape
$$ \prod_i S(U_i) \to \prod_{i,j} S(U_i \cap U_j) \to \prod_{i,j,k} S(U_i \cap U_j \cap U_k) \to \dots $$
The differentials in this complex are certain antisymmetrizations of the restriction maps of the sheaf (writing down the details is tedious, but they are easy to look up and the idea is easy to imagine, I'd argue).
Now we can deduce how the sheaf cohomology groups can be read as "local-to-global"-obstructions! The sheaf properties of $S$ immediately show that the above complex has zeroeth cohomology equal to $S(M)$: If an element in $\prod_i S(U_i)$ is in the kernel of the first map, that means its components are equal on intersections. By the gluing axiom this means they glue to an element in $S(M)$, and by the local identity axiom this element is unique.
We can try to do the same with elements $(x_I) \in \prod_{i_1,\dots,i_k} S(U_{i_1} \cap \dots \cap U_{i_k})$ in the higher groups of the complex: Here, the condition of being in the kernel of the differential will be some complicated equations on the restrictions of the elements $x_I$ to intersections of the $U_i$; whatever these look like, they are basically the higher-order-equivalent of "the components of $(x_I)$ agree on intersections". And, of course, these "agreeing-on-intersections"-conditions are necessary for $(x_I)$ to come from an element in the $(k-1)$-part of the complex, the higher-order-equivalent of gluing.
But now, a nontrivial sheaf cohomology group tells us: Even if the higher-order-"agreeing-on-intersections"-condition is fulfilled, the $(x_I)$ may not be higher-order-gluable! Now, this viewpoint does not directly read as a local-to-global condition, but it is a kind of "very-local-to-a-bit-less-local"-condition, in the sense that we try to glue data from more refined intersections to less refined intersections.