-1

How do I squash multiple commits into one? I'm working on a fix for an issue on a open open source project and I did the following so far:

  • I forked the repo on GH
  • cloned the fork onto my machine
  • checked out a branch, added the upstream repo (the repo that I forked), made changes to the code, git add, git commit, git push -u origin my_branch .
  • logged onto GitHub and made the pull request.
  • After that, I made multiple changes to my pull request via GitHub.com and committed each one.

One of the mods now whats me to combine all these commits into one, but I have no idea how. I also need to make some more changes to the code. But this time, I want to make the changes locally (instead of doing it on GitHub). So, how can I update my local repo so that it reflects that changes I made on GitHub?

Thank you!

Moe82
  • 1
  • 2

1 Answers1

0

OK, so the fork belongs entirely to you. So first say git pull locally to sync the fork down to your local machine. Then, still working locally, use the technique described here (regret type 1) to squash all the commits on your branch into a single commit: git reset --soft down to the commit where you started the branch, and immediately git commit. Finally, git push to sync back up the fork. The pull request will be modified accordingly.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thank you so much! Explained everything perfectly. – Moe82 Oct 21 '20 at 13:58
  • You might have to say `git push -f` in the last step, because the remote repo doesn't like when you "rewrite history". But the fork belongs to you, so there is no problem with forcing it to obey. – matt Oct 21 '20 at 13:59