Pregunta

this should be a relatively trivial problem, I just (very) new to using Git, so please forgive the simple question. I need to get some updates along our Development branch into a Feature branch because they are critical, however there's a minor complication in that some of the updates on Feature were pushed previously, but not all of them.

I've been reading git manuals, I've had a look around and I'm not 110% I have this entirely down yet. I'm not certain how this works...


What I've Done:

  1. I created a local Feature branch, forking it off our Development branch at {B}
  2. I worked on it for a bit. I committed some changes three times {I,J,K}.
  3. I pushed these three commits, as a new remote branch.
  4. I had to merge Feature into Development {E}.
  5. I worked on Feature a bit further, committing twice again {L,M}.
  6. Something came up, and I then had to push three commits to Development {F,G,H}, critical to Feature.

What We Have:

A ---- B ---- C ---- D ---- E ---- F ---- G ---- H [DEVELOPMENT]
        \                 /
         \               /
          I ---- J ---- K ---- L ---- M  [FEATURE]

Therefore, our current state:

  • Local/Feature is at {M}
  • Remote/Feature is at {K}
  • Local/Development is at {H}
  • Remote/Development is at {H}

My IDE reports my Feature branch is 2 Ahead {L,M}, and 4 Behind {E,F,G,H}.


What We Want:

We need the most recent updates committed to Development to be drawn into Feature, so I can keep going. It should look something like:

A ---- B ---- C ---- D ---- E ---- F ---- G ---- H [DEVELOPMENT]
        \                 /                       \
         \               /                         \
          I ---- J ---- K ----- ------ ------ ----- L ---- M  [FEATURE]

Further Details

  • I'm the only one working on the Feature branch anywhere.
  • No one has pulled my previously pushed commits to Feature.

How do I fix this solution, without making the remote branch system in particular ugly or fragmented? This should be a very simple rebase or merge operation from the Feature branch, one command, right?

git rebase Development (then correct any conflicts)?

I don't know what this will do to the remote, and I really don't want to break anything for anyone. If anyone could enlighten me on how to do this properly, I'd appreciate it. :)

¿Fue útil?

Solución

You will alway want to keep your feature branch up to date in respect to the development branch.

This can be done either by pull or by rebase. Since you already pushed, rebase would create new potential problems.

So simply do:

git merge development

from your feature branch. The result is that all your critical commits are now part of the feature branch, exactly as you want it.

Otros consejos

First you have to fix your local branch:
git checkout M

Bring your local feature branch up to date with either
git rebase H or git merge H (I prefer rebase)

At this point, you may have to fix some conflicts with git mergetool, just follow the instructions.

Now you can update the remote feature branch from your local feature branch:
git push origin feature_branch:feature_branch

You only have to worry about remote branches when you push, everything else is done locally. On the last command for example, the only affected remote branch is the one after the : , in that case feature_branch.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top