Jan Wrobel
Jan Wrobel

Reputation: 7099

How to squash multiple local git commits that are interleaved with remote commits

When I'm working on a large feature that takes me few days to implement I do many small commits to my local git repository and also pull others' changes from the remote master repository. After the feature is complete, my local git repo looks somehow like:

  1. Local commit: Last step of the feature X
  2. Remote commit: B
  3. Local commit: part of the feature X
  4. Local commit: part of the feature X
  5. Remote commit: A
  6. Local commit: the first step of the feature X.
  7. ...

Now, I would like to push all local commits to the remote repo as a single commit that adds the feature X. Squashing commits with 'git rebase' won't work in this case, because remote commits not done by me (2 and 5) would also need to be squashed, which is not an option.

The only way that I managed to figure out was to have a clean branch with only remote commits, issue 'git diff' against my local development branch and apply a resulting patch onto the clean branch. Then commit patched changes and push. Is there a better way?

Upvotes: 1

Views: 1686

Answers (1)

Jan Wrobel
Jan Wrobel

Reputation: 7099

I found the answer: git rebase -i actually allows to reorder commits, and when all local commits are reordered to be in sequence (not interleaved with remote commits), they can be all squashed into one.

Upvotes: 3

Related Questions