1

I have a simple repository with two branches: master and branch
branch has been created a long time ago and commits have been accumulated on both branches.
There are two main ways to merge: merge and rebase merge.
I won't describe first case, I'm interested in second.
rebase merge will apply branch commits just after HEAD of master.
Log history is rewritten, I'm looking for a better way to merge respecting chronology.

Suppose I have this kind of repository.
1 has been created before 2, 2 has been created before 3 and so on...

  7        6
  5        4
  3        2
  1--------1
master   branch

I would like to perform a perfect merge respecting dates:

  7        7
  6        6
  5        5
  4        4
  3        3
  2        2
  1--------1
master   branch

I'm aware of git rebase -i, is there a way to perform this automatically ?
Also, I think this will create troubles in other local cloned repositories because of rewritten history.
Is there a way to safely perform this ?

1 Answer 1

3

I'm aware of git rebase -i, is there a way to perform this automatically ?

I don't believe there is a way to do this operation automatically, short of creating a custom script to handle the logic (probably not worth it in the long run). $ git rebase -i (interactive rebase) is the way to go here.

Also, I think this will create troubles in other local cloned repositories because of rewritten history. Is there a way to safely perform this ?

If this repository and these commits are published somewhere, yes that could be a huge issue and pain for others to pull down and work through. The "safe" way would be to not rewrite history. I know that's not what you're looking for, but typically the juice is not worth the squeeze with rewriting git history, especially when dealing with commits that'll get pushed to remote repositories with other contributors.

2
  • Does git rebase -i in branch to reorder commits then merge onto master will create troubles in cloned repositories ? Sep 15, 2015 at 15:30
  • @LeFlou: Yes. You're rewriting history, and everyone will have to reconcile what they've done against that new history, which has wide and far-reaching impacts.
    – Makoto
    Sep 15, 2015 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.