1

I have the following 2 branches, A should be rebased on top of B:

(Ancestor) -> A1 -> A2 -> A3
          \
           -> B1

I'm trying to squash all commits in A into 1 commit:

(Ancestor) -> B1 -> A123

However when I use git rebase with squash commit command, git still tries to rebase one commit at a time, so it start rebasing A1, ask me to resolve conflict, then rebase A2, as resolve conflict again, ... This waste a lot of time in rebasing branches.

My idea rebase would be to squash A1, A2, A3, directly, then only ask to resolve conflict between A3 & another head. I can do it manually with 2 git commands, but this is also not convenient. Is it possible to do it automatically with one command?

Thanks a lot for your help

tribbloid
  • 4,026
  • 14
  • 64
  • 103

1 Answers1

0

The number of commands is not really that important, I think, because you can always put however many commands it takes into a script or alias. What matters is the amount of interaction needed.

Thus, I think what you want is a soft reset style squash commit (see here and here) followed by a rebase. To get it down to one interaction, you will need to automate the message made for the first squash commit, probably by concatenating the three (or however many) to-be-squashed commits, and then use an interactive rebase with the sequence editor set to a script of your own that replaces the pick command with reword. Actually writing each of these pieces is something I leave to you, but I'll note that:

  • git show --format=%B --no-patch --no-notes <commit> will get you the full commit message for the given commit.

  • Replace show with log and a commit range to get several messages; or use git rev-list <range> to get the IDs printed to standard output, then loop using show, to allow you inject your own (varying) text between each. (For fixed text, possibly including additional % conversions, you can simply use the --format argument.)

  • The sequence editor can be any script in any language; it just needs to open the interactive rebase commands file, modify it, and write it back out to the file.

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775
  • Looks like you are right. Its not supported natively in git, but I'm using intelliJ IDEA and recently did a lot of merging pull requests, maybe this can be a plugin feature – tribbloid Mar 21 '16 at 16:59