Domanda

My topic branch is about 20 commits ahead of where I branched from.

I would like to automatically squash all these commits into the first commit after the branch.

I know I can do this interactively with rebase, but I don't want to interact, just fire off the command.

È stato utile?

Soluzione

You could do it this way:

git reset --soft HEAD~20
git commit -m "massive commit"
  • The first command moves your topic branch 20 commits back, but preserves the changes in the index (and the working tree)
  • Then you create a single commit with all the changes.

A quick way to find the exact commit you want to reset to is to do

git merge-base <topicbranch> <otherbranch>

If the output of that is <commit-ish>, you can then do

git reset --soft <commit-ish>

Altri suggerimenti

Why not just check out your original branch, and git merge --squash <other branch>?

Then, git commit will give you a chance to edit the combined commit message.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top