If the energy of the photon is conserved along a geodesic why is it redshifted I have learnt through the Killing vector that the energy of a photon is conserved along a geodesic. But then my question is why is the photon redshifted. It is loosing energy in that way because frequency is proportional to the energy. So isn't there a contradiction.
Edit after comments
Caroll says that though the geodesic eqn (or rather by just solving the Euler Lagrange eqn for the time coordinate) you have $(1-R/r) \dot{t} =constant$ and the constant is interpreted as the energy. So I understand that energy is conserved along a geodesic and hence the question of photon getting redshifted and loosing energy.
Edit after the answer
I have 2 issues:
1). In SR the components of 4 momentum were always the total relativistic energy and momentum. In GR if I don't write the 4 momentum vector in the local lorentz basis, then aren't the components of it still the total energy and momentum. It would be in arbitrary basis $p^\mu=(p^0,p^1,p^2,p^3)$. Then aren't $p^0$ and $p^1$ still the total energy and momentum. I understand that $E=p.U$ a scalar under general transformation so it will always be the energy but what I can't see is that when in SR the individual components were the energy and momentum, then why in GR when the 4 Momentum is written in arbitrary coordinates, it's individual components not the total energy and momentum (if they are not).
2). I understand that observers at different places measure different frequencies and thus different energy (that means I was right, the usual energy is not conserved along the geodesic), but then what is that "other energy $p_0$" which is conserved (that you mention ). How is that energy different (essentially why is $p^0$ not the energy).
Some Related questions
Is Energy conserved in General Relativity
How does Equivalence Principle imply a Curved Space-Time?
 A: The answer by Michael Seifert to a similar question is a literal answer to your question. However, you're saying that the following conceptual issue is still confusing you:

But Caroll says that though the geodesic eqn (or rather by just solving the Euler Lagrange eqn for the time coordinate) you have $(1−R/r)\dot{t}$=constant and the constant is interpreted as the energy. So I understand that energy is conserved along a geodesic and hence the question of photon getting redshifted and loosing energy.

When a spacetime has a Killing vector, we get a corresponding conserved quantity for test particles. When the Killing vector is timelike, we say loosely that this is interpretable as a conserved energy, but this is just a loose interpretation. Actually the fit with newtonian notions of energy is not very close. And in any case, it can't be the energy that would be measured by any observer whatsoever, because that depends on the motion of the observer.
RedGiant says:

Do you know that energy conservation law does not hold in GR?

This is wrong as applied here. GR has no global conservation of the energy in an entire spacetime (except in special cases like asymptotically flat spacetimes), which is a completely different statement. Here we're talking about a conserved quantity for a test particle.
The answer by stuffu is also wrong. The conserved energy of a test particle in a stationary spacetime cannot be described in terms of newtonian concepts like kinetic and potential energy. There is a nice discussion of this sort of thing, at an elementary level, in Taylor and Wheeler, Exploring Black Holes, p. 3-19.
Stuffu says:

In an accelerating frame there is a potential field.

This doesn't make sense. These words don't mean anything in relativity.
A: This is a good question and it tests ones understanding of red shift owing to gravity. The summary of what I am about to say can be stated as follows:
the gravitational red-shift of light can best be seen as a statement about the differing rates of clocks at different locations.
Now I will unpack this. The statement about conservation can be put in two (equivalent) ways.

*

*If the metric is independent of time (in the chosen coordinates) then $p_0$ is conserved along a geodesic, where ${\bf p}$ is the 4-momentum of the particle concerned (whose worldline is the given geodesic).


*If the vector field $\bf K$ satisfies Killing's equation (that is to say, it is a Killing vector field) then ${\bf K} \cdot {\bf p}$ is constant along the worldline of the particle.
In view of this conservation, the term "energy" is widely applied to the quantity $p_0$. The energy (defined this way) of a photon is everywhere the same along its geodesic, in a stationary spacetime.
However, this "energy" is not necessarily the one which an observer will observe. Suppose an inertial observer whose 4-velocity is ${\bf u}$
carries some sort of energy-detecting device. When they measure the photon with 4-momentum $\bf p$, the energy they will observe in their own frame is given by $-{\bf p} \cdot {\bf u}$. (If you prefer index notation, then you can use $-{\bf p} \cdot {\bf u} = - p_\mu u^\mu$; and I am using metric signature $(-1,1,1,1)$.)
Now consider two such observers at different locations, and suppose the spacetime is stationary and they are both at rest relative to the coordinates. They will not necessarily have the same $u^0$. In fact, they usually will not if the metric is different at the two locations. For we have
$$
u_\mu u^\mu = -c^2
$$
so
$$
g_{\mu \nu} u^\mu u^\nu = - c^2
$$
for either observer. Hence if $u^i = 0$ (spatial part zero, so observer not moving relative to the coordinates) then
$$
g_{0 0} (u^0)^2 = - c^2   \;\;\; \text{(no sum)}
$$
hence
$$
u^0 = \sqrt{ - c^2 / g_{00} }
$$
Let the two observers be A and B. We have $p_0$ is the same at A and B.
So the observed energies are
$$
E_{\rm A} = -p_\mu u^\mu_{\rm A} = -p_0 u^0_{\rm A} = -p_0 c \sqrt{-1/g_{00}(A)}
$$
$$
E_{\rm B} = -p_\mu u^\mu_{\rm B} = -p_0 u^0_{\rm B} = -p_0 c \sqrt{-1/g_{00}(B)}.
$$
Hence the ratio of these observed energies is
$$
{E_{\rm B} \over E_{\rm A}} = \sqrt{ g_{00}(A) \over g_{00}(B) }
$$
This is the gravitational redshift in the case of a stationary spacetime.
Overall, what is happening is that the two observers look at a light wave having some $p_0$ which is the same everywhere, but they interpret this as differing frequency when compared with their own clocks, and differing energy similarly.
Further remark
Components of 4-vectors (or higher rank tensors) are always frame-dependent. In SR this fact does not perturb our physical intuition too much. This is because the components correspond closely to what some inertial observer will observe. But in GR the situation is different because of the great generality of the coordinate choices available, and the possibility that spacetime itself may be dynamic. In GR this implies that no component (of any 4-vector or higher rank tensor) should ever be attached too strongly to a physical concept. For example, $p_0$ is energy-like, and so is $p^0$, but both will change in odd ways if you adopt an unusual coordinate system, or if the spacetime is not stationary in the first place.
The situation of a stationary but non-flat case is intermediate between SR and the full generality of GR. Here one may, with caution, talk as if some component or other corresponded to a concept such as energy or momentum, especially when there is a conservation. So this is why $p_0$ (or $-p_0$) earns the right to be called "energy", but $p^0$ does not. But I would insist on those inverted commas. To get something straightforwardly called energy, consider what an inertial observer at some given event would observe. That is given by $-{\bf p} \cdot {\bf u}$ as explained above.
A: In an accelerating frame there is a potential field. Thing moving in said field 'upwards' lose kinetic energy and gain potential energy.
In said potential field 'upper' clocks run faster than 'lower' clocks.
If a clock is fast, it measures a frequency to be slow. The frequency of a photon for example.
A device that measures energy of a photon ignores the potential energy of a photon.
I think everything about the photon has been explained by those above effects.
A: Suppose you fire a photon with energy E at a galaxy 100 million light years away.  The Hubble constant is roughly 2 cm/s per light year, so the galaxy is moving away at 2 Mm/s, still slow enough to avoid a relativistic calculation, so the redshift is about 2 Mm/s / 300 Mm/s = 1/150.
Now if we shoot light at that galaxy and they provide a typically puckish alien answer by reflecting it back at us unaltered, the light is redshifted once going there and once back so it has lost 1/75 of its total energy.  The universe has stolen our conservation of energy, right?
Well, not exactly.  The mirror on their end had mass m, and our light had momentum E/c, so their mirror gets kicked with a velocity (using Newtonian momentum mv) of E/mc, which is doubled when the light is sent back.  And from our perspective their mirror was already moving at 2 Mm/s, so the change of kinetic energy is the new kinetic energy = 1/2 m (2 Mm/s + E/mc)2 minus the old kinetic energy 1/2 m (2 Mm/s)2 giving us about 1/2 m * 4 * 2 Mm/s * E/mc = (2 Mm/s / c) * 2E.  Notice that first part, 2 Mm/s / c, is our redshift, so the mirror, regardless of its mass, has acquired the amount of kinetic energy that was lost by the light.
Bottom line: if you're seeing redshifted light, everything it does to push you away seems like it's making a larger amount of energy than it ought to people in the frame from which it was sent.  And if you're seeing blueshifted light, then anything it does to slow you down seems to take away a lot of energy from their point of view, which then has to be released somehow.
