0

I rebased some branch X to develop, but I didn't push it (remote repo doesn't know about rebasing).

Next, I made some changes. Simultanetously, my collegue did some push to develop.
I also would like now (after my local rebase and some changes) do push to develop. Moreover, I would like to flatten this rebase and changes to exactly one commit (I know about squash but I can't use it in this case).

What should I do ? I think that something like that:

git add --update
git commit -m "rebase + my changes"   
git fetch develop
git rebase origin/develop
(solving potential conflicts)
?git commit? 
git push 

Am I right ?

  • Possible duplicate of [Squash all your commits in one, before a pull request in github](http://stackoverflow.com/questions/31668794/squash-all-your-commits-in-one-before-a-pull-request-in-github) – Tatsuyuki Ishi Mar 09 '17 at 14:47

1 Answers1

0

The sequence of commands you gave would be close, but it will not create a single commit for the rebase + local changes. To start, you might as well fetch, and the diagrams below will assume you've kept your remote refs in sync with the remote repo. So if there's anything you haven't fetched, go ahead and fetch it. Then:

It sounds like you had

A --- B --- C <--(develop)(origin/develop)
       \
        X1 --- X2 --- X3 <--(branch_x)

Next you rebased from branch_x to develop (...so hopefully there was no remote branch_x?), and someone else pushed changes to develop:

A --- B --- C --- D <--(origin/develop)
             \
              X1' --- X2' --- X3' <--(develop)

And you made some more changes from your local develop.

(Your proposed command list starts with add and commit so I gather those aren't even locally staged yet...):

A --- B --- C --- D <--(origin/develop)
             \
              X1' --- X2' --- X3' <--(develop)
                                 \
                                  o <--WORKING TREE

So you want to combine X1', X2', X3', and o into a single commit whose parent is D, right?

Well, to start go ahead and commit your local changes.

git add --update
git commit

(Not sure why you're using --update, but as long as you don't mean to add new files, it's fine.)

A --- B --- C --- D <--(origin/develop)
             \
              X1' --- X2' --- X3' --- Y <--(develop)

Now you say you can't do a squash, but it's unclear to me why that would be. It seems to me from here the easiest thing to do is

git checkout origin/develop
git merge --squash develop
# handle conflicts
git commit -m "rebase + my changes"
git branch -f develop

which gives you

A --- B --- C --- D <--(origin/develop)
                   \ 
                     X1X2X3Y <--(develop)

And now you can push.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52