Thank you so much for the response, After understanding things for a while, I tried to follow the steps and came across a problem:
- After deleting the commits with git reset --hard HEAD~1000 command then I used - git rebase upstream/master #till here it was all okay and I thought I just needed to force push the changes now, but when I did that it says - git push --force origin master Problem: * ! [remote rejected] master -> master (refusing to allow an OAuth App to create or update workflow `.github/workflows/ci-sage.yml` without `workflow` scope)error: failed to push some refs to 'https://github.com/KuldeepBorkar/sympy.git'* I was not able to find any perfect solution to this. Therefore, I thought asking this before would be good or else I would run into another mess againš¢ Thank you for your help and guidance : ) On Tuesday, 22 February 2022 at 18:51:15 UTC+5:30 Oscar wrote: > On Tue, 22 Feb 2022 at 07:58, Kuldeep Borkar > <kuldeepbo...@gmail.com> wrote: > > > > Hi SymPy Community, > > > > Few days ago I ran into a problem regarding Git and GitHub; > > > > Problem: Whenever I try to make a PR by creating a new branch from > master branch, the past commits showed up in the commit history (which I > think is the commits made from the master branch) . > > > > Description: Every time I made a PR the commit history was like 12-14 > commits and it was quite bad since even if I was making a few changes then > also along with my recent 1 commit there were past 12 commits with it in > the commit history. > > I tried searching as much as possible what to do then I learned about > rebase to edit the commit history and I tried that but I was able to see > just the 1 recent commit there and nothing else so, I was confused a lot. > > Now, > > I think the problem probably is that I made some commits from the master > branch itself and then even if I do something like fetch and merge, update > the forked repository then also every time I try to create a new PR from a > new branch created from master branch then also it is showing that past > commits. > > I realize this was my big mistake to make commits from master branch and > I will avoid making any change in the master branch in future. > > > > Is there any solution to this so that I can make PR and have the commits > only related to the changes I made and not the past commits. > > Firstly as you now realise each PR should be made from a separate > branch and you shouldn't commit directly to your master branch. You > want the master branch in your fork to be only a pristine copy of the > master branch in the main sympy repo. To start make sure that you have > the main repo as the remote upstream: > > git remote add upstream https://github.com/sympy/sympy.git > > Now you update your master branch locally with: > > git fetch upstream > git checkout master > git rebase upstream/master > > You could use merge rather than rebase here. I use rebase because I > never want to create a merge commit but if you haven't committed to > your master branch then it shouldn't create a merge commit. If you do > accidentally commit to your master branch then always using rebase > here ensures that your accidental commits are always the last commits > on the branch. > > Then when you want to create a PR you can update your master branch > (as above) and then make a new branch from it: > > git checkout master > git checkout -b pr_branch > > Of course you don't have to start your new branch from your local > master branch. You could instead do: > > git fetch upstream > git checkout upstream/master > git checkout -b pr_branch > > Then you have a local branch for the PR but it's created directly from > the upstream master branch so it won't have any of the extra commits > in it. This is the first solution to your problem if you just want to > create a PR right now. > > If you want to get rid of the commits from your master branch then you > can do it like this but be careful because this is not reversible and > it is easy to mess this up. I'm assuming that you do not want to keep > any of the changes that you have made to your master branch and are > happy to delete them forever with no chance of recovery. > > **Make sure that you have a backup of any valuable work and that your > working directory is clean before doing this.** > > git checkout master > git reset --hard HEAD~1000 # Completely delete the last 1000 commits > git rebase upstream/master # Update from upstream again > > I'm assuming that 1000 commits is enough to remove all the commits > that you have added but you can use a larger number if needed. > > Now you've fixed your master branch locally but if you've been pushing > your master branch to your fork on GitHub then that also needs to be > fixed. A simple "git push" won't work now because you've "rewritten > the history". Instead a force-push is needed: > > git push --force origin master > > Both "reset --hard" and "push --force" are commands that should be > used sparingly. Make sure you understand what you are doing before > using them. > > -- > Oscar > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/2901d4b4-49fe-491b-8a8c-b9fe2a8790bfn%40googlegroups.com.