1

First of, I rebased on master:

A - B - C
         \
          D' - E'

Then, the master got reverted few commits back, so remotely it looks like:

A - B

While locally, my dev branch still has the C commits. Is it safe to do a

git pull origin master git rebase master

Won't some of the commits duplicate? What is the proper way to get back to

A - B
      \
       D' - E'
Maciaz
  • 1,084
  • 1
  • 16
  • 31

2 Answers2

0

One way to achieve the desired history is to use

git rebase -i origin/master

and drop the unwanted commits (C) from the list.

The answer to "is it safe?" is "yes, if done right".

j6t
  • 9,150
  • 1
  • 15
  • 35
0

Solution to the problem

There is a simple solution using --onto

git rebase --onto B C

this mean :

Rebase the commit reachable from HEAD whose parent is C on top of B.

Safety of the propose solution

In your case,

    master
        |
A - B - C
         \ 
          D' - E'
               |
              HEAD

git pull origin master

 master
    |
A - B - C
         \ 
          D' - E'
               |
              HEAD

git rebase master

will just do nothing. As you can see your HEAD is already base on master. So git will tell you there is nothing to do.

In git, everything local (no push) is safe since you have no unversionned local modification, just put some temp tag or branches if you are not sure of what you do. You can always come back to these if you mess up your tree.

jota
  • 23
  • 7