Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github commits pile up after squash merge of pull request

  1. I have a fork of another repo @github.
  2. did some code and issued a pull request to upstream
  3. upstream master merged with squash option
  4. now next pull request includes new code and the older commits as well. So they increasingly pile up.

What can I do with it?

  • repos are completely in sync in terms of code
  • still github badge at the top shows that my fork is xx commits ahead of the upstream
  • I tried to merge upstream to my repo (with no effect because they are sync)
  • I'm not sure if rebase may help, but there are my commits and other people's commits. So it is a mess there and I'm not sure what to rebase.
like image 717
Alexander T Avatar asked Nov 19 '22 15:11

Alexander T


2 Answers

If upsteam changes your commit history (squashing commits) in their repo, you have to do the same in your repo - reset master to upsteam master and force push - losing your individual commits in the process, but gaining the squashed commit in exchange.

git switch master
git fetch
git reset --hard upsteam/master
git push -f origin

This is a destructive operation and force pushing to master may even be blocked in Github repository settings, but sometimes it has to be done.

If your upstream is going to squash your commits anyway, you may want to consider squashing them on your end before creating pull request.

like image 198
JockX Avatar answered Dec 09 '22 10:12

JockX


I'm not sure if rebase may help, but there are my commits and other people's commits. So it is a mess there and I'm not sure what to rebase.

Do a git log to see where is your next feature branch (from which you want to do your second pull request):

git log --graph --format=format:"%h% - %aD (%ar)%d%n %s - %an" --abbrev-commit --all --branches

Refresh your upstream:

git fetch upstream

Rebase only your commits on top of the pull request target branch

git rebase --onto upstream/master yourFirstCommit~1 yourBranch

That will rebase every commits after "yourFirstCommit" (as seen in the git log graph above) up to your branch HEAD.
Once those commits are on top of upstream/master, your pull request (after a git push --force) will be updated, showing only your commits.

like image 45
VonC Avatar answered Dec 09 '22 09:12

VonC