git pull and friends, was git pull + src/sharefiles.mk
Subject: git pull and friends, was git pull + src/sharefiles.mk
From: Leo Butler
Date: Sat, 20 Aug 2011 12:39:05 +0000
Andreas Eder <andreas_eder at gmx.net> writes:
> Robert Dodier wrote:
>>You wrote some notes about Git which was posted to this list.
>>Can you update the notes to indicate how to deal with pull vs rebase?
>
> Yes, I'd second this. Git is also new to me and sometimes behaves rather
> unexpectedly.
> So, a mini tutorial would be rather welcome. (Yes I know the freely
> available literature about git.)
Ok, I will try to snatch some time in the next week to update the notes.
In the meantime, here are a few pointers (please feel free to correct me
on any misunderstandings):
-a branch X in a git repo R can `track' another a branch X' in another
repo R'; however, these branches are distinct in that their
HEAD/history may diverge.
-when branch X tracks X', repo R will contain a branch R'/X'. The
command
git branch -r
will list these branches.
-git fetch updates the "remote" branches like R'/X', but it does not alter
the "local" tracking branches like X.
-git merge attempts to merge the history of X and R'/X',
this will include the history of which HEAD is on which
branch at each commit, so a merge preserves as much history
as possible, in some sense. A cost of this is that the history tends
to look like spaghetti after a while.
-git rebase attempts to rewrite the history of X so that
all commits on X come after any commits on R'/X'. In short
a history that looks like
____ X
/
-------- R'/X'
is changed to a history that looks like
_____ X
/
-------- R'/X'
At that point, merging the two branches is trivial (there can be no
conflicts) and git gives this trivial type of merge a name: it's a
fast-forward.
-the command
git pull --rebase
executes git fetch, followed by git rebase. Since rebasing re-writes
history, this is *not* the default for git pull. (The potential harm in
re-writing history is, if you someone else is already basing work on
that history, then when it is re-written you force them to adapt--which
can be quite messy and complicated.)
-the command
git pull --ff-only
will do a git fetch, then a git merge but it will only do a fast-forward
merge (in other words, the merge will succeed only if the histories look
like
____ R'/X'
/
---- X
so the HEAD of X can be fast-forwarded to that of R'/X').
--
Leo Butler <l_butler at users.sourceforge.net>
SDF Public Access UNIX System - http://sdf.lonestar.org