git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Updating not actual branch
@ 2013-03-12 13:22 Jan Pešta
  2013-03-12 15:19 ` Konstantin Khomoutov
  2013-03-12 16:03 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Pešta @ 2013-03-12 13:22 UTC (permalink / raw)
  To: git

Hi All,

I have a question if there is a posibility tu update a branch which is not
actual working copy.

I have following situation:

A - B - C - I - J                       master
               \ - D - E - F               feature 1
                                 \ G - H     feature 2 (working copy)

I would like tu update whole tree with latest changes in master

A - B - C - I - J                                              master
                           \ - D* - E* - F*                  feature 1
                                                   \ G* - H*     feature 2
(working copy)


Is there some way how to do it without swithing to each branch and update
them manually?

Thanks,
Jan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Updating not actual branch
  2013-03-12 13:22 Updating not actual branch Jan Pešta
@ 2013-03-12 15:19 ` Konstantin Khomoutov
  2013-03-12 16:03 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Khomoutov @ 2013-03-12 15:19 UTC (permalink / raw)
  To: Jan Pešta; +Cc: git

On Tue, 12 Mar 2013 14:22:00 +0100
Jan Pešta <jan.pesta@certicon.cz> wrote:

> I have a question if there is a posibility tu update a branch which
> is not actual working copy.
> 
> I have following situation:
> 
> A - B - C - I - J                       master
>                \ - D - E - F               feature 1
>                                  \ G - H     feature 2 (working copy)
> 
> I would like tu update whole tree with latest changes in master
> 
> A - B - C - I - J                                              master
>                            \ - D* - E* - F*                  feature 1
>                                                    \ G* - H*
> feature 2 (working copy)
> 
> 
> Is there some way how to do it without swithing to each branch and
> update them manually?

It's partially possible to do: you are able to forcibly fetch a remote
object into any local branch provided it's not checked out.  Hence, in
your case you'll be able to update any branch excapt for "feature 2".

To do this, you could use the explicit refspec when fetching, like this:

$ git fetch origin +src1:dst1 '+blooper 1:feature 1'

(Consult the `git fetch` manual for more info on using refspecs.)

One possible downside is that I'm not sure this approach would play
nicely with remote branches, if you have any.  I mean, direct fetching
into local branches will unlikely to update their matching "upstream"
remote branches.

So supposedly a better way to go would be to write a script which would
go like this:
1) Do a simple one-argument `git fetch <remotename>` to fetch from
   the specified remote and update its remote branches.
2) Run `git for-each-ref`, and for each local branch found first check
   whether it's currently checked out (that is, HEAD points at it)
   and ignore the branch if it is; otherwise do `git update-ref`
   updating the branch pointer from its upstream branch -- referring to
   that using the <ref>@{upstream} syntax.
   (Consult the gitrevisions manual for more info on this syntax.)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Updating not actual branch
  2013-03-12 13:22 Updating not actual branch Jan Pešta
  2013-03-12 15:19 ` Konstantin Khomoutov
@ 2013-03-12 16:03 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2013-03-12 16:03 UTC (permalink / raw)
  To: Jan Pešta; +Cc: git

Jan Pešta <jan.pesta@certicon.cz> writes:

> I have following situation:
>
> A - B - C - I - J                       master
>                \ - D - E - F               feature 1
>                                  \ G - H     feature 2 (working copy)
>
> I would like tu update whole tree with latest changes in master
>
> A - B - C - I - J                                              master
>                            \ - D* - E* - F*                  feature 1
>                                                    \ G* - H*     feature 2
> (working copy)
>
>
> Is there some way how to do it without swithing to each branch and update
> them manually?

With these asterisks I would assume that you are rebasing feature #n
on top of updated master.  As rebasing requires you to have a
working tree, so that you can resolve potential conflicts between
your work and work done on the updated upstream, you fundamentally
would need to check out the branch you work on.

In the case you depicted where feature-1 is a complete subset of
feature-2, you are rebasing both of them, and you do not end up in
a nasty conflict, you could start from this state:

    A---B---C master
             \
              D---E---F feature-1
                       \
                        G---H feature-2

update the master from the upstream:

    $ git checkout master ; git pull

    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H feature-2

rebase feature-2 on top of the updated master:

    $ git rebase master feature-2

                                G'--H' feature-2
                               /
                      D'--E'--F'
                     /
    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H

and finally repoint feature-1 to its updated version:

    $ git branch -f feature-1 F'

                                G'--H' feature-2
                               /
                      D'--E'--F' feature-1
                     /
    A---B---C---I---J master
             \
              D---E---F
                       \
                        G---H

Depending on the interaction between commits C..J and C..F, your
rebasing of feature-2 may end up not losing any of D', E' or F'.
Imagine the case where J was committed on the upstream by applying
the same patch as the original E; E' will become redundant and the
result of your "git rebase master feature-2" may look like this
instead:

                            G'--H' feature-2
                           /
                      D'--F'
                     /
    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H

Or J could remove something E depends on, in which case you may have
to add it back with a new commit X when you rebase feature-2, like
so:

                                    G'--H' feature-2
                                   /
                      D'--X---E'--F'
                     /
    A---B---C---I---J master
             \
              D---E---F feature-1
                       \
                        G---H

Because you cannot mechanically decide where the tip of updated
feature-1 has to be, you would need to use your brain to decide
where to repoint the tip of feature-1 in the last step.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-12 16:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-12 13:22 Updating not actual branch Jan Pešta
2013-03-12 15:19 ` Konstantin Khomoutov
2013-03-12 16:03 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).