Skip to contentSkip to conversation

How to update a cloned git repository

DISCUSSION Joachim Schmitz 5 participants 14 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi folks

Probably a beginner's question...

If I did a
git clone git://guthub.com/git/git.git
and worked on some own branches of pu
git checkout pu;git checkout -p mybranch;hack;hack;...;git commit -a -s
how to update my repository once the the one on github changed?
A plain
git pull
or
git fetch;git merge
keeps failing on my with lots of conflicts, none of which relate to any of the changes I did (and hence wouldn't know how to resolve)

Bye, Jojo

#1 lore raw
Quoted 8 lines · Joachim Schmitz

Hi folks

Probably a beginner's question...

If I did a
git clone git://guthub.com/git/git.git
and worked on some own branches of pu
git checkout pu;git checkout -p mybranch;

I guess you meant "git checkout -b mybranch" (not -p).

Quoted 6 lines

hack;hack;...;git commit -a -s

how to update my repository once the the one on github changed? A plain git pull or git fetch;git merge keeps failing on my with lots of conflicts, none of which relate to any of the changes I did (and hence wouldn't know how to resolve)

Short answer: don't work on pu. Work on master unless you have a good reason not to.

Longer answer: the pu branch in git.git is often re-written, hence the commit on which you started hacking once existed in git.git's pu, but it probably no longer is.

You cloned this:

--A---B---C <-- origin/pu

Hacked to this

         origin/pu
          |
          v

--A---B---C---D---E <-- mybranch

and the next fetch resulted in something like this:

    B'---C'---D'---F <-- origin/pu

/
--A---B---C---D---E <-- mybranch

while you could have expected that if origin/pu had just been fast-forwarded with a new commit F:

            F <-- origin/pu
           /

--A---B---C---D---E <-- mybranch

As a result, "git merge" computes a common ancestor very far backward in history. Instead of merging only your changes with new pu content, it merges the old history of pu (plus your changes) with the new history of pu, and you get spurious conflicts.

The solution is to rebase your changes (and only yours). My advice is to rebase them on master, like this (replace 42 by the number of commits you want to rebase in HEAD~42):

  git rebase HEAD~42 --onto origin/master

Once you did this, you can start using "git pull" (or "git pull --rebase") as usual.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#2 lore raw
Quoted 10 lines

From: Matthieu Moy [mailto:[email protected]]
Sent: Tuesday, September 11, 2012 1:06 PM
To: Joachim Schmitz
Cc: [email protected]
Subject: Re: How to update a cloned git repository

Quoted 2 lines · Joachim Schmitz

Hi folks

Quoted 8 lines
Quoted 6 lines

Probably a beginner's question...

If I did a
git clone git://guthub.com/git/git.git
and worked on some own branches of pu
git checkout pu;git checkout -p mybranch;

I guess you meant "git checkout -b mybranch" (not -p).

Yes, of course...

Quoted 9 lines
Quoted 6 lines

hack;hack;...;git commit -a -s

how to update my repository once the the one on github changed? A plain git pull or git fetch;git merge keeps failing on my with lots of conflicts, none of which relate to any of the changes I did (and hence wouldn't know how to resolve)

Short answer: don't work on pu. Work on master unless you have a good reason not to.

There are some changes in pu, that I need as the basis, namely my setitimer patch and my 2nd mkdir patch, which haven't yet made it into the master branch (and in the setitimer case not out of pu)

Quoted 33 lines

Longer answer: the pu branch in git.git is often re-written, hence the commit on which you started hacking once existed in git.git's pu, but it probably no longer is.

You cloned this:

--A---B---C <-- origin/pu

Hacked to this

         origin/pu
          |
          v

--A---B---C---D---E <-- mybranch

and the next fetch resulted in something like this:

    B'---C'---D'---F <-- origin/pu

/
--A---B---C---D---E <-- mybranch

while you could have expected that if origin/pu had just been fast-forwarded with a new commit F:

            F <-- origin/pu
           /

--A---B---C---D---E <-- mybranch

As a result, "git merge" computes a common ancestor very far backward in history. Instead of merging only your changes with new pu content, it merges the old history of pu (plus your changes) with the new history of pu, and you get spurious conflicts.

Quoted 5 lines

The solution is to rebase your changes (and only yours). My advice is to rebase them on master, like this (replace 42 by the number of commits you want to rebase in HEAD~42):

  git rebase HEAD~42 --onto origin/master

For pu this would be similar?

Quoted 2 lines

Once you did this, you can start using "git pull" (or "git pull --rebase") as usual.

Like this?
git pull --rebase HEAD~42

So far I create patches, wiped out the entire repository, cloned, forked and applied the changes, pretty painful.

#3 lore raw
Quoted 8 lines · Joachim Schmitz
Quoted 4 lines

From: Matthieu Moy [mailto:[email protected]] ..
Short answer: don't work on pu. Work on master unless you have a good reason not to.

There are some changes in pu, that I need as the basis, namely my setitimer patch and my 2nd mkdir patch, which haven't yet made it into the master branch (and in the setitimer case not out of pu)

And that is not a good reason, either.

In general, it is a good habit to get into to base your changes on the oldest point release they may want to be used with. For example, if you really wanted to, you could make sure your Tandem changes can be back-merged all the way down to v1.7.6 by forking your own branch from there, queuing your changes like mkdir, itimer on top. And you develop and test your changes on that branch, without pulling from or rebasing it on top of my tree where random other things happen that won't affect you an iota. A recent change to add the new "--set-upstream-to" option to "branch" command does not have any platform-specific bits, and for the purpose of the "port to Tandem" topic, keeping up to date with such a change in my tree is pointless, for example. To make sure that the result is still usable with recent releases, you can create a throw-away merge between your work (that is forked from a stable base) and my tip every once in a while, test the result, and discard the throw-away merge when you are done. Any breakage in your series you find in such an integration test is to be fixed on your branch, not on top of such a throw-away merge.

It might be the case that nobody cares if the resulting patches will not apply to and usable with 'master' or older integration branches, so in the particular case of "Tandem", choosing a stable fork point that is older than 'master' may not make much sense, though.

#4 lore raw
Quoted 20 lines

-----Original Message-----
From: Junio C Hamano [mailto:[email protected]]
Sent: Tuesday, September 11, 2012 6:01 PM
To: Joachim Schmitz
Cc: 'Matthieu Moy'; [email protected]
Subject: Re: How to update a cloned git repository

Quoted 8 lines · Joachim Schmitz
Quoted 4 lines

From: Matthieu Moy [mailto:[email protected]] ..
Short answer: don't work on pu. Work on master unless you have a good reason not to.

There are some changes in pu, that I need as the basis, namely my setitimer patch and my 2nd mkdir patch, which haven't yet made it into the master branch (and in the setitimer case not out of pu)

Quoted 6 lines

And that is not a good reason, either.

In general, it is a good habit to get into to base your changes on the oldest point release they may want to be used with. For example, if you really wanted to, you could make sure your Tandem changes can be back-merged all the way down to v1.7.6 by forking

The first version I ever made available for NonStop is 1.5.12, so no reason for me to go back.
On the other hand I see nothing in my patches that would not easily backport to much older releases, as the code I touched is either newly created by me (e.g. compat/mkdir.c) or pretty old (compar/win32/poll.c).

Quoted 15 lines

your own branch from there, queuing your changes like mkdir, itimer on top. And you develop and test your changes on that branch, without pulling from or rebasing it on top of my tree where random other things happen that won't affect you an iota. A recent change to add the new "--set-upstream-to" option to "branch" command does not have any platform-specific bits, and for the purpose of the "port to Tandem" topic, keeping up to date with such a change in my tree is pointless, for example. To make sure that the result is still usable with recent releases, you can create a throw-away merge between your work (that is forked from a stable base) and my tip every once in a while, test the result, and discard the throw-away merge when you are done. Any breakage in your series you find in such an integration test is to be fixed on your branch, not on top of such a throw-away merge.

Quoted 4 lines

It might be the case that nobody cares if the resulting patches will not apply to and usable with 'master' or older integration branches, so in the particular case of "Tandem", choosing a stable fork point that is older than 'master' may not make much sense, though.

My goal here is that the next stable release has as much of my patches integrated as possible, so I have much less work when porting, ideals just hitting 'make'...

So far my poll patches are still needed. And then, but not earlier, my plain NonStop specific ones (like a section in Makefile and some adjustments in git-compat-utils.h) , these don't make much sense earlier.

Bye, Jojo

#5 lore raw
In reply to Joachim Schmitz
Quoted 4 lines · Joachim Schmitz

Like this?
git pull --rebase HEAD~42

So far I create patches, wiped out the entire repository, cloned, forked and applied the changes, pretty painful.

I think a 'git pull --rebase' should usually work even for 'pu'.

But sometimes pu may have changes that take away the basis for your patch (i.e, not just a restructure) then you'd get conflicts.

#6 lore raw
In reply to Joachim Schmitz
Quoted 8 lines · Joachim Schmitz
Quoted 4 lines

From: Matthieu Moy [mailto:[email protected]]

Short answer: don't work on pu. Work on master unless you have a good reason not to.

There are some changes in pu, that I need as the basis, namely my setitimer patch and my 2nd mkdir patch, which haven't yet made it into the master branch (and in the setitimer case not out of pu)

Then, work on the tip of the topic branch you depend on instead of pu. These are more stable, as they will be rewritten only if this particular topic branch changes.

Quoted 3 lines
Quoted 1 line
  git rebase HEAD~42 --onto origin/master

For pu this would be similar?

Yes. If you insist in working on top of pu, you can rebase --onto origin/pu.

Quoted 2 lines

Like this?
git pull --rebase HEAD~42

That would be "git fetch" and then "git rebase", as I don't think "git pull --rebase" would allow you to specify the starting point for rebase.

Quoted 2 lines

So far I create patches, wiped out the entire repository, cloned, forked and applied the changes, pretty painful.

This is conceptually similar to what "git rebase" does, but it does it in a slightly more efficient way ;-).

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#8 lore raw
In reply to a message not in the archive

[ Re-adding git@vger in Cc, I guess it was meant to be so ]

Quoted 5 lines · Joachim Schmitz
Quoted 3 lines

Then, work on the tip of the topic branch you depend on instead of pu. These are more stable, as they will be rewritten only if this particular topic branch changes.

These are not available from git hub. Or are they? How?

I think they exist in some of the repos junio pushes to, but I don't remember how/which one.

Anyway, you can easily get it from the commit that merges the branch (it's the-merge-commit^1).

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Like this?
git pull --rebase HEAD~42

That would be "git fetch" and then "git rebase", as I don't think "git pull --rebase" would allow you to specify the starting point for rebase.

OK, I'll try that next time then. Like this?

	git fetch;git rebase HEAD~42 --onto origin/pu

That should work, yes.

In general, when you have a somehow complex workflow, I recommand fetch+(merge|rebase) over pull. It gives you more flexibility, and the opportunity to check what you fetched before starting the merge.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

So far I create patches, wiped out the entire repository, cloned, forked and applied the changes, pretty painful.

This is conceptually similar to what "git rebase" does, but it does it in a slightly more efficient way ;-).

Indeed ;-)

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#9 lore raw
Quoted 7 lines

From: Matthieu Moy [mailto:[email protected]]
Sent: Tuesday, September 11, 2012 2:41 PM
To: Joachim Schmitz
Cc: git
Subject: Re: How to update a cloned git repository

[ Re-adding git@vger in Cc, I guess it was meant to be so ]

Oops, yes it was meant to.

Quoted 20 lines
Quoted 5 lines · Joachim Schmitz
Quoted 3 lines

Then, work on the tip of the topic branch you depend on instead of pu. These are more stable, as they will be rewritten only if this particular topic branch changes.

These are not available from git hub. Or are they? How?

I think they exist in some of the repos junio pushes to, but I don't remember how/which one.

Anyway, you can easily get it from the commit that merges the branch (it's the-merge-commit^1).

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Like this?
git pull --rebase HEAD~42

That would be "git fetch" and then "git rebase", as I don't think "git pull --rebase" would allow you to specify the starting point for rebase.

Quoted 8 lines
Quoted 2 lines

OK, I'll try that next time then. Like this?

	git fetch;git rebase HEAD~42 --onto origin/pu

That should work, yes.

In general, when you have a somehow complex workflow, I recommand fetch+(merge|rebase) over pull. It gives you more flexibility, and the opportunity to check what you fetched before starting the merge.

OK, thanks.

I'm sure I'll have more questions later though ;-)

#10 lore raw
In reply to Matthieu Moy
Quoted 8 lines · Matthieu Moy

[ Re-adding git@vger in Cc, I guess it was meant to be so ]

Quoted 4 lines · Joachim Schmitz
Quoted 3 lines

Then, work on the tip of the topic branch you depend on instead of pu. These are more stable, as they will be rewritten only if this particular topic branch changes.

Quoted 7 lines
Quoted 1 line

These are not available from git hub. Or are they? How?

I think they exist in some of the repos junio pushes to, but I don't remember how/which one.

Anyway, you can easily get it from the commit that merges the branch (it's the-merge-commit^1).

I think it is the-merge-commit^2; contrib/git-resurrect.sh might be of interest, too.

#11 lore raw
Quoted 18 lines

From: Junio C Hamano [mailto:[email protected]]
Sent: Tuesday, September 11, 2012 6:06 PM
To: Matthieu Moy
Cc: Joachim Schmitz; git
Subject: Re: How to update a cloned git repository

Quoted 10 lines · Matthieu Moy

[ Re-adding git@vger in Cc, I guess it was meant to be so ]

Quoted 5 lines · Joachim Schmitz
Quoted 3 lines

Then, work on the tip of the topic branch you depend on instead of pu. These are more stable, as they will be rewritten only if this particular topic branch changes.

These are not available from git hub. Or are they? How?

Quoted 8 lines
Quoted 5 lines

I think they exist in some of the repos junio pushes to, but I don't remember how/which one.

Anyway, you can easily get it from the commit that merges the branch (it's the-merge-commit^1).

I think it is the-merge-commit^2; contrib/git-resurrect.sh might be of interest, too.

Sorry you lost me, this is greek to me...

#12 lore raw
Quoted 4 lines · Joachim Schmitz
Quoted 2 lines

I think it is the-merge-commit^2; contrib/git-resurrect.sh might be of interest, too.

Sorry you lost me, this is greek to me...

A commit is an object that contain pointers to its parents. The root commit has no parent. For ordinary commits, there is one parent which is the commit on top of which it was created. For merge commits, there are N commits, the first is the one on top of which the merge was created, and the N-1 next ones are the commits being merged.

commit^ => first parent of commit
commit^1 => same
commit^2 => second parent, i.e. the one merged in commit.

See in git.git:

$ git show cb10ae9433126ef <---------------------------- one commit to study
commit cb10ae9433126efbc4dcc46779d7ef2fe6b1f597
Merge: 13b608a 9aeaab6   <------------------------------- list of parents
Author: Junio C Hamano <[email protected]>
Date:   Tue Sep 11 15:57:04 2012 -0700

Merge branch 'jc/maint-blame-no-such-path' into pu

* jc/maint-blame-no-such-path:
blame: allow "blame file" in the middle of a conflicted merge

$ git show cb10ae9433126ef^1 <-------------------- "previous commit" in origin/pu
commit 13b608a063ce861929322e6bb3862b5364f3fbcf
Merge: fa17a26 bdee397
Author: Junio C Hamano <[email protected]>
Date:   Tue Sep 11 11:50:44 2012 -0700

Merge branch 'dg/run-command-child-cleanup' into pu

* dg/run-command-child-cleanup:
run-command.c: fix broken list iteration in clear_child_for_cleanup

$ git show cb10ae9433126ef^2 <----------------- commit being merged by cb10ae9433126ef
commit 9aeaab6811dce596b4f6141d76f5300359bfd009
Author: Junio C Hamano <[email protected]>
Date:   Tue Sep 11 14:30:03 2012 -0700

blame: allow "blame file" in the middle of a conflicted merge
[...]

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#13 lore raw
In reply to Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Matthieu Moy

Anyway, you can easily get it from the commit that merges the branch (it's the-merge-commit^1).

I think it is the-merge-commit^2;

Right. I forgot that Git counted parents from 1, not 0.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#14 lore raw
In reply to Matthieu Moy
Quoted 4 lines · Matthieu Moy

[ Re-adding git@vger in Cc, I guess it was meant to be so ]

"Joachim Schmitz" <[email protected]> writes:

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

Then, work on the tip of the topic branch you depend on instead of pu. These are more stable, as they will be rewritten only if this particular topic branch changes.

These are not available from git hub. Or are they? How?

I think they exist in some of the repos junio pushes to, but I don't remember how/which one.

You can usually find them here: https://github.com/gitster/git/branches

And Joachim's branch in particular:
https://github.com/gitster/git/tree/js/compat-itimer