Exactness and obstruction in sheaf cohomology 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?
 A: Well of course a sheaf is by definition something that can lift local datas to global ones in the following sense : if $\{U_i\}$ forms a cover of $X$ and if $f_i\in \mathcal{F}(U_i)$ are sections such that $f_i=f_j\in\mathcal{F}(U_i\cap U_j)$ then the $f_i$'s glue together to form a section $f\in\mathcal{F}(X)$ such that $f|_{U_i}=f_i$.
So what might ask what do not glue inside a sheaf ?
Consider a sheaf $\mathcal{F}$ and sections $f_i\in\mathcal{F}(U_i)$ over a cover of $X$, but this time you don't ask for the $f_i$'s to agree on the intersection. Instead you ask for the $f_i$'s to agree up to a given subsheaf. More precisely, let $\mathcal{G}\subset\mathcal{F}$ be a subsheaf and assume that $f_i-f_j\in\mathcal{G}(U_i\cap U_j)$. Does the $f_i$'s "glue" to a section $f\in\mathcal{F}$ ? I put some quotation marks because, of course you can't expect to find $f$ such that $f|_{U_i}=f_i$ (this would implies that $f_i=f_j$). But you can hope to find $f$ such that $f|_{U_i}-f_i\in\mathcal{G}(U_i)$.
(I believe that this problem was first ask by Cousin with the so-called Cousin's problem : assume you have meromorphic functions $f_i$ defined on $U_i$ such that $f_i-f_j$ are holomorphic. Is there a meromorphic function $f$ such that $f|_{U_i}-f_i$ are holomorphic ?)
It turns out that the sheaf $\mathcal{G}$, or rather its $H^1$, contains the obstruction to lift the local data $(f_i)$ to the global one $f$. Indeed, note that if $g_{ij}=f_i-f_j\in\mathcal{G}(U_i\cap U_j)$, then $(g_{ij})$ forms a $1$-cocycle and this cocycle is a trivial in cohomology iff you can find the $f$.
So now, what is the connection with $\Gamma$ not being exact ? Start with the $f_i\in\mathcal{F}(U_i)$ as above, well obviously $f_i$ defines a section $\overline{f_i}\in(\mathcal{F/G})(U_i)$, and the $\overline{f_i}$'s do glue in $\mathcal{F/G}$, since $\overline{f_i}-\overline{f_j}=0\in(\mathcal{F/G})(U_i\cap U_j)$. So you have a well defined element $\overline{f}\in \Gamma(X,\mathcal{F/G})$. Now you can find the $f$ as above iff $\overline{f}$ is in the image of $\Gamma(X,\mathcal{F})\to\Gamma(X,\mathcal{F/G})$.
The short exact sequence $0\to\mathcal{G}\to\mathcal{F}\to\mathcal{F/G}\to 0$ gives rise to the exact sequence
$$0\to \Gamma(X,\mathcal{G})\to\Gamma(X,\mathcal{F})\to\Gamma(X,\mathcal{F/G})$$
the non right exactness of $\Gamma$ means that we cannot extends this exact sequence by $0$, instead the derived functor $H^1(X,\mathcal{G})$ appears :
$$0\to \Gamma(X,\mathcal{G})\to\Gamma(X,\mathcal{F})\to\Gamma(X,\mathcal{F/G})\to H^1(X,\mathcal{G})$$
And the cocycle $(g_{ij})$ constructed above is exactly the image of $\overline{f}$ under the boundary map $\Gamma(X,\mathcal{F/G})\to H^1(X,\mathcal{G})$. Putting together what we said before we see that the following are equivalent :

*

*you can find the global $f$ which "lift" the local data $f_i$

*the cocycle $(g_{ij})$ is trivial, in other words $\overline{f}\in\ker(\Gamma(X,\mathcal{F/G})$ (here we see that cohomology contains the obstruction)

*$\overline{f}$ comes from an $f\in\Gamma(X,\mathcal{F})$,  in other words $\overline{f}\in\operatorname{im}(\Gamma(X,\mathcal{F})\to\Gamma(X,\mathcal{F/G}))$ (here we see that $\Gamma$ does not preserve surjectivity).

A: 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.
