9
  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.
Striezel
  • 3,693
  • 7
  • 23
  • 37
Alexander T
  • 115
  • 7
  • Rebase is lying. Why? Because it alters the commit history. The same holds for squash commits. So a reasonable thing to do would be to ask the upstream NOT to squash commits any more. – Striezel Oct 14 '16 at 21:26

2 Answers2

2

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.

JockX
  • 1,928
  • 1
  • 16
  • 30
1

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.

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