@@ -791,6 +791,78 @@ <h2 id="_output">OUTPUT</h2>
791791</ dd >
792792</ dl > </ div >
793793</ div >
794+ < h2 id ="_note_about_fast_forwards "> Note about fast-forwards</ h2 >
795+ < div class ="sectionbody ">
796+ < div class ="para "> < p > When an update changes a branch (or more in general, a ref) that used to
797+ point at commit A to point at another commit B, it is called a
798+ fast-forward update if and only if B is a descendant of A.</ p > </ div >
799+ < div class ="para "> < p > In a fast-forward update from A to B, the set of commits that the original
800+ commit A built on top of is a subset of the commits the new commit B
801+ builds on top of. Hence, it does not lose any history.</ p > </ div >
802+ < div class ="para "> < p > In contrast, a non-fast-forward update will lose history. For example,
803+ suppose you and somebody else started at the same commit X, and you built
804+ a history leading to commit B while the other person built a history
805+ leading to commit A. The history looks like this:</ p > </ div >
806+ < div class ="listingblock ">
807+ < div class ="content ">
808+ < pre > < tt >
809+ B
810+ /
811+ ---X---A
812+ </ tt > </ pre >
813+ </ div > </ div >
814+ < div class ="para "> < p > Further suppose that the other person already pushed changes leading to A
815+ back to the original repository you two obtained the original commit X.</ p > </ div >
816+ < div class ="para "> < p > The push done by the other person updated the branch that used to point at
817+ commit X to point at commit A. It is a fast-forward.</ p > </ div >
818+ < div class ="para "> < p > But if you try to push, you will attempt to update the branch (that
819+ now points at A) with commit B. This does _not_ fast-forward. If you did
820+ so, the changes introduced by commit A will be lost, because everybody
821+ will now start building on top of B.</ p > </ div >
822+ < div class ="para "> < p > The command by default does not allow an update that is not a fast-forward
823+ to prevent such loss of history.</ p > </ div >
824+ < div class ="para "> < p > If you do not want to lose your work (history from X to B) nor the work by
825+ the other person (history from X to A), you would need to first fetch the
826+ history from the repository, create a history that contains changes done
827+ by both parties, and push the result back.</ p > </ div >
828+ < div class ="para "> < p > You can perform "git pull", resolve potential conflicts, and "git push"
829+ the result. A "git pull" will create a merge commit C between commits A
830+ and B.</ p > </ div >
831+ < div class ="listingblock ">
832+ < div class ="content ">
833+ < pre > < tt >
834+ B---C
835+ / /
836+ ---X---A
837+ </ tt > </ pre >
838+ </ div > </ div >
839+ < div class ="para "> < p > Updating A with the resulting merge commit will fast-forward and your
840+ push will be accepted.</ p > </ div >
841+ < div class ="para "> < p > Alternatively, you can rebase your change between X and B on top of A,
842+ with "git pull --rebase", and push the result back. The rebase will
843+ create a new commit D that builds the change between X and B on top of
844+ A.</ p > </ div >
845+ < div class ="listingblock ">
846+ < div class ="content ">
847+ < pre > < tt >
848+ B D
849+ / /
850+ ---X---A
851+ </ tt > </ pre >
852+ </ div > </ div >
853+ < div class ="para "> < p > Again, updating A with this commit will fast-forward and your push will be
854+ accepted.</ p > </ div >
855+ < div class ="para "> < p > There is another common situation where you may encounter non-fast-forward
856+ rejection when you try to push, and it is possible even when you are
857+ pushing into a repository nobody else pushes into. After you push commit
858+ A yourself (in the first picture in this section), replace it with "git
859+ commit --amend" to produce commit B, and you try to push it out, because
860+ forgot that you have pushed A out already. In such a case, and only if
861+ you are certain that nobody in the meantime fetched your earlier commit A
862+ (and started building on top of it), you can run "git push --force" to
863+ overwrite it. In other words, "git push --force" is a method reserved for
864+ a case where you do mean to lose history.</ p > </ div >
865+ </ div >
794866< h2 id ="_examples "> Examples</ h2 >
795867< div class ="sectionbody ">
796868< div class ="vlist "> < dl >
@@ -936,7 +1008,7 @@ <h2 id="_git">GIT</h2>
9361008</ div >
9371009< div id ="footer ">
9381010< div id ="footer-text ">
939- Last updated 2009-07-09 16:48:59 UTC
1011+ Last updated 2009-08-13 01:22:27 UTC
9401012</ div >
9411013</ div >
9421014</ body >
0 commit comments