0

I have tried git rebase in interactive mode to squash commits. I have also tried git reset in soft mode, then made a single commit.

It seems to have changed my git log. But when I need to push to GitHub, It says could not push, I need to pull first due to divergent branches.

After pulling and then pushing, when I go to GitHub, I find that the number of commits has only increased.

How can I change the history on the commits page of a GitHub repo?

aahnik
  • 1,661
  • 1
  • 11
  • 29
  • For a public branch which is already being shared by others besides yourself, please consider just using `git revert` instead of an interactive rebase, the latter which rewrites history. – Tim Biegeleisen Sep 20 '20 at 04:53
  • Thanks a lot Tim, for this suggestion. It is certainly useful in some of my cases – aahnik Sep 20 '20 at 04:59

2 Answers2

1

At this point

It says could not push, I need to pull first due to divergent branches.

you should do

git push -f 

This will get you the desired result. Hopefully other contributors, if any, on whatever you are working on, don't mind if the commit history has changes.

Suggested reading: Git Push

Shridhar R Kulkarni
  • 6,653
  • 3
  • 37
  • 57
1

It would be better to use git push --force-with-lease.
git push --force-with-lease vs. --force

Chuck Lu
  • 173
  • 12