3

We're learning Git and we're using GitHub as our hosting site.

We all fork the upstream repo and PR our commits up to upstream to get our changes in.

We're trying to learn how to squish our commits to keep the upstream commit history nice and clean(ish).

We commit often :)

So ... if we submit a Pull Request .. and then the project maintainers then add comments on the commit (i.e. doing a code review of the PR) ... the developer(s) then will fix up the issues and push up their commits again.

Is it possible to squish these commits so the PR has only one commit? What happens to the comments in GH (against this PR) ?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

2 Answers2

0

You will have to git push --force (after the rebase squash local: pick the first commit, put a "s" marker on the other commits).

But the PR will still be valid. Its associated history will be updated with the one just pushed (here one squashed commit)

Who does these commands? the person who submitted the PR/extra commits? or the reviewer?

The owner of the fork push as many time as it needs: the comments won't be destroyed, and will actually be part of the squashed commit.
The commits that were previously part of the PR will be marked as "obsolete", replaced by the new commit you just pushed.
The maintainer will then be able to merge the squashed history.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

To squish the commit together:

git rebase -i upstream/master

The -i will activate interactive mode, and you will be able to decide for each commit if you want to squish it with its parent (called "fixup"), or if you want to edit the commit message (called "reword"), or if you want to add/remove/update files in the commit (called "edit").

After you finished rebasing, you will have to force push:

git push -f

However, I think this destroys reviewers' comments on the PR.

William
  • 2,695
  • 1
  • 21
  • 33
  • I'm not worried if the reviewers comments are destroyed ... so that's ok. Who does these commands? the person who submitted the PR/extra commits? or the reviewer? – Pure.Krome Nov 07 '15 at 02:49
  • Anyone who has push privileges on the fork. – William Nov 07 '15 at 02:50