POV-Ray : Newsgroups : povray.off-topic : Git tutorial Server Time
30 Jul 2024 14:27:54 EDT (-0400)
  Git tutorial (Message 7 to 16 of 76)  
<<< Previous 6 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: Re: Git tutorial
Date: 20 Apr 2011 06:08:15
Message: <4daeb08f$1@news.povray.org>
One thing which apparently can't be done with Darcs, Git or Mercurial is 
managing multiple repositories at once.

For example, consider Glasgow Haskell Compiler, which is written in 
Haskell itself. The compiler, interpreter and run-time system are one 
repo, and the various standard libraries it requires are independent 
projects with their own repos, but GHC mirrors a copy of each, lagging 
behind the upstream slightly. The main GHC repo contains a special Bash 
script to do things like update all the sub-repos automatically. The 
existence of this script tells you that there's functionality that Darcs 
itself is failing to provide. (And Git and Mercurial, apparently.)


Post a reply to this message

From: Invisible
Subject: Re: Git tutorial
Date: 20 Apr 2011 06:24:06
Message: <4daeb446$1@news.povray.org>
On 19/04/2011 19:25, Darren New wrote:

> Having spoken with half a dozen people who said "I hate git, it's so
> confusing" and then after showing them this they go "wow, that's really
> easy", I figured it might be worthwhile to show people this. :-)

As an aside, I do envy you to some extent for actually knowing people 
IRL who know how a computer works...


Post a reply to this message

From: Darren New
Subject: Re: Git tutorial
Date: 20 Apr 2011 11:32:32
Message: <4daefc90$1@news.povray.org>
On 4/20/2011 2:44, Invisible wrote:
> I had assumed that all DVCSs were the same, but I now see that at least Git
> and Darcs use fundamentally different models.

GIT stores files, and deduces change sets from those files.

Mercurial stores change sets, and deduces files from those changesets.

> Fundamentally, any version control system tracks changes to files.

No, git actually tracks entire files. Every time you check something in, any 
file you add to staging (i.e., any file with any change) is stored in its 
entirety in the repository. And, technically, *every* file in the entire 
repository is stored, but if you haven't changed it, it has the same sha-1 
name, so it doesn't physically get copied.

Only later do you compress the repository into diffs. But a file can be 
stored as a diff from a different file it was never related to, that was 
created whole-hat *after* you checked in the file it's a diff from.

 > What Git
> appears to be doing is something similar to RCS or CVS, where each file goes
> through a strictly sequential series of "versions", and one version comes
> "before" or "after" another.

Nope. Not even close. git is storing the entire repository on every commit. 
That's the completely boggling idea there.

> It seems that each commit stores the complete
> state of the entire repository.

Yes. So there's no "before" or "after" for files, technically. There's 
before or after for repositories.

> (Presumably as a diff relative to the previous commit,

Nope. It stores the entire repository. Now, if you don't change a file, it 
hashes to the same value, and hence doesn't need to get stored again. But 
the entire file is put into the repository.

That's why git doesn't have a "rename" command. That would imply you're 
storing something other than files in the repository. git looks at the same 
contents disappearing from one part of the directory structure and showing 
up in another and says "Gee, that must have been a rename."  If there are 
minor changes between what disappeared on this commit and what showed up 
somewhere else on that commit, git says "there's a 97% probability this was 
a renamed file."

When you do a "git gc" to collect garbage, it then looks for a good way to 
generate diffs between files, and it looks through all the files (not just 
ancestors) to find good versions to diff from, and it stores the diffs. But 
that's just an storage optmization, just like the fact that it gzips the 
files in the repository is a storage optimization.

If I checked in a configuration file with my name in it, and 2 days later 
deleted it, and then you checked in a similar configuration file with your 
name in it, and then we did a "git gc", it's entirely possible (likely, 
even) that my file would be stored as a diff from your file.

In contrast, it seem Mercurial actually stores a tree of changes.

The only reason git uses a pointer to earlier commits is when you merge 
things, you don't want to apply changes you already applied in an earlier 
merge.

For example, when you merge branch A into branch B, git finds the common 
ancestor (i.e., the point at which you separated B from A in the first 
place), then *generates* the diff between what's now A and where they 
branched, then *applies* that diff to B, and leaves it ready for a commit. 
There's no diff stored before you type "git merge" or after it returns from 
the command line.

Reverting a commit involves either just throwing away the new version, or 
generating a reverse diff and applying it.

That's the thing that throws people about git, apparently. They're thinking 
in terms of diffs, when it's easiest to understand if you just think about 
it in terms of file contents.

> Git then uses "heads" to point to the most recent commit in each branch, or to
> other interesting points in the history.

Right.

> Darcs works completely differently. Darcs doesn't track sequential file
> versions, it tracks change-sets. It defines a "change-set algebra" where
> unrelated changes to the same file are independent, and can be applied or
> reverted independently. Changes to the same part of a file are not
> independent, and can only be applied in sequence. But unrelated changes
> are... unrelated.

Yeah, from the little I read about it, Darcs is another one of those 
"interesting" ideas.  An actual mathematical system for defining a 
repository, like relational algebra did for databases.

> As an example, if I add some comments to file X and commit that, and then I
> add a new function to file X and commit that too, I get two change-sets. I
> can revert adding the comments but still keep the new function, even though
> the latter change happened *before* the former.
>
> As far as I can tell, Git would require me to create a branch where I add
> the comments, and another branch where I add the new code, and then merge
> them back into the main branch, hoping that I don't get any conflicts. To
> me, this seems like a lot more work and a lot more conceptual overhead.

Nah. That's only if you want to have both at once working in parallel. That 
is, if you want one version with the comments but no function, and another 
version with the function but no comments, that's trivial in git. If you 
then want to combine them into a third version that has both comments and 
function, then you merge, which is also trivial unless you changed the same 
lines in both places. (I.e., it's as trivial as any other diff-patch based 
merge.)

> It also seems that when you ask Git to perform a commit, you have to tell it
> which files to record changes for.

Sure. But you can say "add all changes" trivially. Or you can use 
interactive tools to commit just bits and pieces of this and that.

Basically, there's a "staging" area where you build a new copy of the 
repository by including files and directories that are different from what's 
out there already. Then you add those new files and directories to the 
repository and point a commit to the new top-level directory.

> With Darcs, you tell it which files to
> monitor, and when you ask to commit it detects what's changed and
> interactively asks you which differences to include and which ones not to
> include. E.g., I could add comments to file X, add a new function, do a
> commit and interactively split the modifications into two separate commits.
> (It doesn't /always/ work, of course, but mostly it does.)

This is trivial with GIT. I do it all the time. I'll be adding a new 
function, and while testing, realize there's a bug in some other function. 
So when everything works again, I'll do two commits, staging just particular 
hunks (in the diff sense of the word) and do two commits, one for the bugfix 
and one for the new change.

> I wonder how well the illusion of one single sequence of file versions works
> when you have multiple people editing the file in parallel.

There's no single sequence of file versions. Every file is a new version.

Given that it's the repository format used by Linux developers, I think it's 
safe to say it works adequately for multiple people editing the file in 
parallel.

> I would imagine
> the Darcs model works better, because it doesn't try to pretend that file X
> looked like this, and then this, and then this.

Neither does git.

> It just records what edits
> happened, without recording their relative ordering [except where they
> affect the same lines of code]. Git, on the other hand, appears to be trying
> to track what every file in the entire repository looked like in every
> individual commit object.

Yes, but since you have them all, you can recreate the diffs between any two 
versions whenever you want.

> With Darcs, you make a branch by copying the repository. That's it.

In git you make a branch by saying "make a new branch."  That's what boggled 
me about mercurial. Really, I need multiple repositories to let me have a 
stable version and a development version?

> (Although there is an option to build a bunch of symlinks for you instead of
> just copying, to save a bit of disk space. Presumably only on POSIX
> platforms...) You can email individual change-sets around, and this works.
> Getting somebody else's changes just copies all change-sets from their
> repository into yours. You can then resolve any conflicts.

git is exactly the same, except it copies files instead of changes. When you 
say "pull from that repository", it finds each "head" (i.e., branch tip) and 
then recurses through the data structures pulling anything reachable from 
them. Since they're all named after the hashes, if you already have a file 
of the same name, you don't need to copy it. Then it stores the heads for 
the remote repository in a different place of the namespace tree than your 
own heads.

But, really, the only things in the git repository are files (blobs), 
directories (trees), commits (a log message pointing to a tree and maybe 
other commits), and tags (a log message pointing to a commit, possibly 
pgp-signed), and then a bunch of names for specific commits or tags or trees 
(i.e., branch names). There are no diffs. There is no history. There are no 
users.

If you want the log history, you follow pointers from one of the heads thru 
the different commit objects. If you want to see what changed, you run diff 
on the two files you want to know what changed between. If you want a new 
branch, you just modify some files, store them, and point a different name 
at the new commit.

If you want to merge someone's repository into yours, you simply copy from 
them any files or names that they have that you don't, and you're done. 
You're merged.  Now if you want to incorporate their changes into your work, 
you generate a diff between their latest version and some earlier version, 
and apply that diff to your latest version, and you're merged.

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

From: Darren New
Subject: Re: Git tutorial
Date: 20 Apr 2011 11:38:52
Message: <4daefe0c@news.povray.org>
On 4/20/2011 3:08, Invisible wrote:
> One thing which apparently can't be done with Darcs, Git or Mercurial is
> managing multiple repositories at once.

git can do this in a sorta half-assed way. Mercurial apparently can too.


> you that there's functionality that Darcs itself is failing to provide. (And
> Git and Mercurial, apparently.)


-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

From: Darren New
Subject: Re: Git tutorial
Date: 20 Apr 2011 11:40:58
Message: <4daefe8a$1@news.povray.org>
On 4/20/2011 8:38, Darren New wrote:
> On 4/20/2011 3:08, Invisible wrote:
>> One thing which apparently can't be done with Darcs, Git or Mercurial is
>> managing multiple repositories at once.
>
> git can do this in a sorta half-assed way. Mercurial apparently can too.

Wrong button. :-)

http://ssteiner.wordpress.com/2008/12/30/git-subprojects/

The fundamental problem is that all the DVCS systems tend to use crypto 
hashes to identify things. So in git, for example, when you create a 
sub-project, the parent project records where the repository is and what 
commit to check out. If you change the sub-project, the old commit is still 
there; you have just added to it. So the parent project is still going to 
get the old version of the subproject until you tell the parent project 
"hey, go update your pointer to the sub project to be commit 01A73F9E."

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

From: Invisible
Subject: Re: Git tutorial
Date: 20 Apr 2011 11:49:57
Message: <4daf00a5$1@news.povray.org>
On 20/04/2011 16:40, Darren New wrote:

> The fundamental problem is that all the DVCS systems tend to use crypto
> hashes to identify things. So in git, for example, when you create a
> sub-project, the parent project records where the repository is and what
> commit to check out. If you change the sub-project, the old commit is
> still there; you have just added to it. So the parent project is still
> going to get the old version of the subproject until you tell the parent
> project "hey, go update your pointer to the sub project to be commit
> 01A73F9E."

The problem Git seems to have is that it uses heads to keep track of 
things. Delete the head and the corresponding commit drops off the face 
of the Earth.

Darcs manages a set [as in set theory] of changes. You don't need to 
keep updating a "pointer" to point to the latest one or anything. I'd be 
surprised if no over VCS has thought of this.


Post a reply to this message

From: Invisible
Subject: Re: Git tutorial
Date: 20 Apr 2011 12:03:49
Message: <4daf03e5$1@news.povray.org>
>> I had assumed that all DVCSs were the same, but I now see that at
>> least Git
>> and Darcs use fundamentally different models.
>
> GIT stores files, and deduces change sets from those files.
>
> Mercurial stores change sets, and deduces files from those changesets.

Doesn't appear to me that that's what happens, from what little 
Mercurial documentation I've read.

>> Fundamentally, any version control system tracks changes to files.
>
> No, git actually tracks entire files.

Fundamentally, VCS are about tracking changes. Git might *implement* 
that by storing the entire file, but *logically* what you're trying to 
do is keep track of what you changed.

> And, technically, *every* file in the entire repository is stored.

Yes, I gradually game to that realisation. Git is managing the entire 
repo as a strictly linear sequence of unumbered versions. (Until you 
explicitly create branches, anyway.)

>> (Presumably as a diff relative to the previous commit,
>
> Nope. It stores the entire repository. Now, if you don't change a file,
> it hashes to the same value, and hence doesn't need to get stored again.
> But the entire file is put into the repository.

How odd... Still, if you're not worried about the internal 
implementation, logically Git is versioning the whole repo as one unit, 
and that's all you need to know.

> That's why git doesn't have a "rename" command.git looks at the
> same contents disappearing from one part of the directory structure and
> showing up in another and says "Gee, that must have been a rename." If
> there are minor changes between what disappeared on this commit and what
> showed up somewhere else on that commit, git says "there's a 97%
> probability this was a renamed file."

o_O

OK, wow. I thought having to tell Darcs when I rename stuff was 
inconvenient, but this just sounds insane...

> The only reason git uses a pointer to earlier commits is when you merge
> things, you don't want to apply changes you already applied in an
> earlier merge.

And here I was thinking it was so you can revert to earlier versions if 
you want. You know - the entire purpose for a VCS to exist in the first 
place? ;-)

> Yeah, from the little I read about it, Darcs is another one of those
> "interesting" ideas. An actual mathematical system for defining a
> repository, like relational algebra did for databases.

It sounds simple enough. If this change affects line X and that change 
affects line Y, they are independent.

Ah, but wait. What if some change adds or removes lines? If change X 
adds a new line between lines 50 and 51 then change Y no longer affects 
line 150, it now affects line 151. But X and Y are still independent.

There's more to it than meets the eye. Of course, if you just want to 
*use* Darcs, you just edit stuff and it "just works".

>> As far as I can tell, Git would require me to create a branch where I add
>> the comments, and another branch where I add the new code, and then merge
>> them back into the main branch, hoping that I don't get any conflicts. To
>> me, this seems like a lot more work and a lot more conceptual overhead.
>
> Nah. That's only if you want to have both at once working in parallel.

Isn't "working on both at once" kind of the entire point of distributed 
version control?

> That is, if you want one version with the comments but no function, and
> another version with the function but no comments, that's trivial in
> git. If you then want to combine them into a third version that has both
> comments and function, then you merge, which is also trivial unless you
> changed the same lines in both places. (I.e., it's as trivial as any
> other diff-patch based merge.)

And if you merge the comments branch into the main branch, and then 
somebody adds more stuff to the comments branch, then what?

>> It also seems that when you ask Git to perform a commit, you have to
>> tell it which files to record changes for.
>
> Sure. But you can say "add all changes" trivially. Or you can use
> interactive tools to commit just bits and pieces of this and that.

With Darcs, I tell it what files to watch, and then when I've finished 
editing stuff, I say "record this" and it shows me every modified line 
of every file and asks which modifications to keep. Git doesn't support 
recording half a file modification, and doesn't even figure out which 
files changed.

> This is trivial with GIT. I do it all the time. I'll be adding a new
> function, and while testing, realize there's a bug in some other
> function. So when everything works again, I'll do two commits, staging
> just particular hunks (in the diff sense of the word) and do two
> commits, one for the bugfix and one for the new change.

Given that Git can only record the new file or the old one, how is that 
possible?

>> I wonder how well the illusion of one single sequence of file versions
>> works when you have multiple people editing the file in parallel.
>
> There's no single sequence of file versions. Every file is a new version.
>
> Given that it's the repository format used by Linux developers, I think
> it's safe to say it works adequately for multiple people editing the
> file in parallel.

This boggles my mind. Apparently I /don't/ understand how Git works at 
all, because the way it seems to work precludes two people touching the 
same file at the same time...

>> It just records what edits
>> happened, without recording their relative ordering [except where they
>> affect the same lines of code]. Git, on the other hand, appears to be
>> trying
>> to track what every file in the entire repository looked like in every
>> individual commit object.
>
> Yes, but since you have them all, you can recreate the diffs between any
> two versions whenever you want.

That's my point. If multiple people are editing the same files, you do 
*not* have all the changes.

>> You can email individual change-sets around, and this works.
>> Getting somebody else's changes just copies all change-sets from their
>> repository into yours. You can then resolve any conflicts.
>
> git is exactly the same, except it copies files instead of changes.

And the "minor detail" that if 200 people edit the same file, that's 200 
separate branches which have to be manually merged back together again.

> If you want to merge someone's repository into yours, you simply copy
> from them any files or names that they have that you don't, and you're
> done. You're merged.

It would be nice if Darcs worked that way.

> Now if you want to incorporate their changes into
> your work, you generate a diff between their latest version and some
> earlier version, and apply that diff to your latest version, and you're
> merged.

What a backwards way to look at it.


Post a reply to this message

From: Darren New
Subject: Re: Git tutorial
Date: 20 Apr 2011 12:24:02
Message: <4daf08a2@news.povray.org>
On 4/20/2011 8:49, Invisible wrote:
> The problem Git seems to have is that it uses heads to keep track of things.
> Delete the head and the corresponding commit drops off the face of the Earth.

Yes. That's why you shouldn't do that.

First, deleting a head that you can't reach from anywhere else requires you 
to answer a confirmation, just like anything else. Second, the *files* are 
still there. You just might not know what they're called. They're probably 
still around at least a couple of weeks before git cleans them up. I.e., 
there are well-documented ways to recover from this if you do it accidentally.

On the other hand, if you work on something and decide it wasn't a good 
idea, you can delete the branch and no harm no done. Darcs apparently 
requires you to copy the entire repository before you even *start* making 
changes if you want to recover.

> Darcs manages a set [as in set theory] of changes. You don't need to keep
> updating a "pointer" to point to the latest one or anything. I'd be
> surprised if no over VCS has thought of this.

But that's exactly why you need to start a new repository if you want a new 
branch. If you clone a repository in Darcs, make a bunch of changes, then 
accidentally delete the repository, you're in even worse shape than if you 
delete a branch in git.

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

From: Darren New
Subject: Re: Git tutorial
Date: 20 Apr 2011 12:55:24
Message: <4daf0ffc@news.povray.org>
On 4/20/2011 9:03, Invisible wrote:
> Doesn't appear to me that that's what happens, from what little Mercurial
> documentation I've read.

I don't know. All the mercurial documentation I've read talks about change sets.

> Fundamentally, VCS are about tracking changes.

Fundamentally, they're about controlling versions. :-)

> Git might *implement* that by
> storing the entire file, but *logically* what you're trying to do is keep
> track of what you changed.

I think it depends. If I want version 1.0 that was released, I don't really 
care what changed to get there. I want that version.  There's uses for 
changes, and uses for storing what you stored.

The advantage of storing what's actually there is you can write all kinds of 
better tools to tell you the differences. For example, you can diff any two 
files to get a compressed copy of the file. If I change a file to include an 
additional 500 lines, then change it to delete 498 of them, the third 
version is going to get stored as a 2-line diff from the first version, not 
a 498-line diff from the second version.

Basically, you're storing absolutes and deducing differences, rather than 
storing differences and deducing absolutes. That means when you want to know 
what changed between release candidate 3.5RC2 and the version 4.2 that Fred 
compiled over on *his* machine, you can just compare the two. You don't have 
to reconstruct anything first.

> Yes, I gradually game to that realisation. Git is managing the entire repo
> as a strictly linear sequence of unumbered versions. (Until you explicitly
> create branches, anyway.)

Or until you clone it, yes.

>>> (Presumably as a diff relative to the previous commit,
>>
>> Nope. It stores the entire repository. Now, if you don't change a file,
>> it hashes to the same value, and hence doesn't need to get stored again.
>> But the entire file is put into the repository.
>
> How odd... Still, if you're not worried about the internal implementation,
> logically Git is versioning the whole repo as one unit, and that's all you
> need to know.

Yes, basically. That's why you can sign just the tag blob and be sure you've 
signed every file that that tag refers to.

> OK, wow. I thought having to tell Darcs when I rename stuff was
> inconvenient, but this just sounds insane...

Why? You don't have to tell git you renamed something.

>> The only reason git uses a pointer to earlier commits is when you merge
>> things, you don't want to apply changes you already applied in an
>> earlier merge.
>
> And here I was thinking it was so you can revert to earlier versions if you
> want. You know - the entire purpose for a VCS to exist in the first place? ;-)

Well, yes, it gives you a way to find those commits. But in theory you could 
look up any commit by hash code and say "give me that version" whether it's 
earlier or later or completely unrelated to what you have now. Indeed, 
that's exactly how branches work. When you start a new branch, all you're 
doing is storing the commit sha-1 into a new file named after the branch.

> It sounds simple enough. If this change affects line X and that change
> affects line Y, they are independent.

Yeah, until you get binary objects in there. :-)

>>> As far as I can tell, Git would require me to create a branch where I add
>>> the comments, and another branch where I add the new code, and then merge
>>> them back into the main branch, hoping that I don't get any conflicts. To
>>> me, this seems like a lot more work and a lot more conceptual overhead.
>>
>> Nah. That's only if you want to have both at once working in parallel.
>
> Isn't "working on both at once" kind of the entire point of distributed
> version control?

Only if you want to work on both at once in the same repository.

If you're working in a different repository, you don't need to start a new 
branch.  Branches are nothing but names for commits. You technically never 
need to use any branch at all if you want to type in a sha-1 every time.


>> That is, if you want one version with the comments but no function, and
>> another version with the function but no comments, that's trivial in
>> git. If you then want to combine them into a third version that has both
>> comments and function, then you merge, which is also trivial unless you
>> changed the same lines in both places. (I.e., it's as trivial as any
>> other diff-patch based merge.)
>
> And if you merge the comments branch into the main branch, and then somebody
> adds more stuff to the comments branch, then what?

Then you get a merge and then more changes on the comments branch. And if 
you merge the comments branch *again*, *that* is when git uses the parent 
pointers in the commit objects to figure out which files to diff in order to 
get the patches to the parent.

A--B--C--D--E--F--G--H--I
    \     |      /
     Q--R/--S--T/

So you started with A, changed to B, branched B and made a change to create 
Q, then R. In the mean time, I changed B to be C.  Now I merge your R back 
to my C. This looks back, sees B is the common ancestor, so diffs R against 
B and applies it to C, then creates D with C and R as parent commits. (Each 
letter is a commit, which includes the state of the entire repository.)

Now you keep working on R without incorporating my B->C change, creating S 
and T. I change D to include E and F. Now I merge your work again.

Git looks at F, follows it back to D, to C and R, and sees that R is a 
common ancestor of both F and T. So it diffs T against R, applies those 
diffs to F, and creates G.  You can then delete the branch that points to T 
safely without losing anything.

It's *super* straightforward to understand what merges do in git.

And if someone comes up with a better diff algorithm, no problem. The 
algorithm to do the diff during a merge isn't built into the repository.

> With Darcs, I tell it what files to watch, and then when I've finished
> editing stuff, I say "record this" and it shows me every modified line of
> every file and asks which modifications to keep. Git doesn't support
> recording half a file modification,

Yes it does.  Indeed, you can even go back and retroactively say "oh, those 
two commits? The second one should have come first, and the first one should 
be broken up into these three commits."

As I said, I do this all the time.

 > and doesn't even figure out which files changed.

Yes it does. It compares the working directory against the staging directory 
and the head to say "these files are changed and unstaged, those are changed 
but already staged, and those are unchanged."

It's just a two-step process. You can build up the thing you want to commit, 
and then finally commit it.  It sounds like Darcs needs you to do that all 
in one step.

Git does it the other way around. First it asks you what modified lines you 
want to put in the commit (and puts them in the staging area), then it 
creates the commit (based on the staging area).

>> This is trivial with GIT. I do it all the time. I'll be adding a new
>> function, and while testing, realize there's a bug in some other
>> function. So when everything works again, I'll do two commits, staging
>> just particular hunks (in the diff sense of the word) and do two
>> commits, one for the bugfix and one for the new change.
>
> Given that Git can only record the new file or the old one, how is that
> possible?

The staging area lies between the repository and the working directory. So I 
check out some branch, and that copies it to the WD and maybe clears the 
staging area. The staging area is basically a commit that's not yet in the 
repository.

Now I make changes to the WD.

Then I use something like "git add" to add all the changes from the WD to 
the staging directory. Or I use "git add -i" (or, more likely, the GUI) to 
diff the WD against the staging area (or the repository), pick (say) three 
of the five diff hunks, and then create a new temp file that holds the 
repository with those three diff hunks applied, which I then put in the 
staging area.  When I have everything the way I like, I commit the change, 
which copies the staging area into the repository and then adds a commit 
object pointing to it.

>>> I wonder how well the illusion of one single sequence of file versions
>>> works when you have multiple people editing the file in parallel.
>>
>> There's no single sequence of file versions. Every file is a new version.
>>
>> Given that it's the repository format used by Linux developers, I think
>> it's safe to say it works adequately for multiple people editing the
>> file in parallel.
>
> This boggles my mind. Apparently I /don't/ understand how Git works at all,
> because the way it seems to work precludes two people touching the same file
> at the same time...

Sure. But you're thinking git tracks diffs. That's exactly the point. If I 
change the file, and you change the file, then now there's three files. The 
original, the new one I have, and the new one you have.  When we go to merge 
it, we create number four, which is your new one with the differences 
between my version and the original applied.

It works because if there's no merge conflicts, then my diff applied to your 
file and your diff applied to my file creates the same file.

>> Yes, but since you have them all, you can recreate the diffs between any
>> two versions whenever you want.
>
> That's my point. If multiple people are editing the same files, you do *not*
> have all the changes.

Well, no, obviously. Welcome to DVCS.  If you don't give me your files, I 
can't see them. This is true of changes you don't push in Darcs and 
mercurial too. Maybe I'm misunderstanding what you're trying to say.

Darcs *is* distributed, right? If you change a file and check it into your 
local repository, and I change it and check it into my local repository, I 
can't see your changes and you can't see mine until we connect the 
repositories again, right?

> And the "minor detail" that if 200 people edit the same file, that's 200
> separate branches which have to be manually merged back together again.

And this differs from any other VCS how?

Note that if you're trying to *push* changes to a remote repository, you 
have to do it to a branch where nobody else has branched off since you did. 
In other words, if I say "update my repository to the DEV branch on the 
company's central reposityro", and I make changes, and someone else changes 
the DEV branch to point to a later version, I can no longer push my changes 
into the DEV branch. Instead, I have to fetch down the new DEV branch, merge 
my changes, then push the newly merged commit back up. Look up "fast-forward 
merge" in the git docs if you care.

But basically what it's saying is if you're *pushing* changes to a 
repository (i.e., there's no human there checking the merges) then you can't 
do a two-parent merge commit. You have to create the two-parent merge commit 
on your own machine, *then* push it up to the server. Sorta.

>> If you want to merge someone's repository into yours, you simply copy
>> from them any files or names that they have that you don't, and you're
>> done. You're merged.
>
> It would be nice if Darcs worked that way.

Right. In Darcs, you have to merge all the changes. In git, you have to 
merge all the changes.

>> Now if you want to incorporate their changes into
>> your work, you generate a diff between their latest version and some
>> earlier version, and apply that diff to your latest version, and you're
>> merged.
>
> What a backwards way to look at it.

Only if you're used to looking at source control as a series of diffs to 
start with. But that's (A) exactly what makes git hard to understand and (B) 
exactly what makes git brilliant. :-)

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

From: Darren New
Subject: Re: Git tutorial
Date: 20 Apr 2011 13:11:44
Message: <4daf13d0$1@news.povray.org>
On 4/20/2011 9:03, Invisible wrote:
> Fundamentally, VCS are about tracking changes. Git might *implement* that by
> storing the entire file, but *logically* what you're trying to do is keep
> track of what you changed.

Or, as an alternate example, say you've been working and every day you 
commit before lunch and you commit before you go home, even if it's not 
working, just so it gets backed up. And you implement two functions, and you 
write code on that, and then realize you should have put that first function 
elsewhere, and you don't need the second function at all, and the other code 
should be in separate objects, and etc etc etc.

And at the end of the week, you have 50 messy changes committed.

With git, you can say "OK, go diff the current version against where I 
branched, and give me exactly one commit with all the changes I need." It's 
trivial to do that in git and then say "now commit *that* change for 
everyone else to see, and abandon all the intermediate changes."

I don't know how you'd do something like that in mercurial or darcs that 
store *changes* in the repository.

-- 
Darren New, San Diego CA, USA (PST)
   "Coding without comments is like
    driving without turn signals."


Post a reply to this message

<<< Previous 6 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.