1

Ive been asked to squash the commits on my pull request on github. When i run

git rebase -i HEAD~5

It looks like this

pick bcbb30d My commit comment
pick 8564706 Other persons commit comment
pick c99bdd2 Other persons commit comment
pick 07bb5b9 Other persons commit comment
pick 2bcff6f Other persons commit comment
pick 77a5076 My commit comment

As I only want to squash MY commits, is it ok to put 'squash' against all of mine but one (leaving it as 'pick') and have the other people's commits left as 'pick' too? Will this only squash my commits?

1
  • Be aware that you are rewriting the repo history when you squash your commits. If you dealing with revisions that are already on the remote (probably your case since you are pulling) the remote will only accept your push if you force it (-f). And this is specially problematically if you are not working alone (and other persons already had the history you changed). Commented Oct 17, 2013 at 14:16

2 Answers 2

3

Try something like this

pick 8564706 Other persons commit comment
pick c99bdd2 Other persons commit comment
pick 07bb5b9 Other persons commit comment
pick 2bcff6f Other persons commit comment
pick bcbb30d My commit comment
squash 77a5076 My commit comment

You are free to reorder commits as well as squash them. Therefore, you should probably put your commits on top of the others, assuming there are not inter-commit dependencies.

Sign up to request clarification or add additional context in comments.

2 Comments

do I have to put my most recent commit as the 'squash' commit?
No, but it doesn't really matter, since you are combining your two commits into one commit. If you change the order, it still ends up as the same thing.
2

Assuming the patches would apply cleanly, you can reorder them in the editor you get from the git rebase -i command, and then squash only yours:

pick 8564706 Other persons commit comment
pick c99bdd2 Other persons commit comment
pick 07bb5b9 Other persons commit comment
pick 2bcff6f Other persons commit comment
pick bcbb30d My commit comment
squash 77a5076 My commit comment

You will now get an editor to fix you (combined) commit message.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.