-1

I have forked a github repository in order to contribute a few pull requests. I checked out this forked repo and worked some time with it.

Now I have the issue that whenever I create some branch from master, change one or two files, commit those and want to create a pull request from this, I have a lot of unwanted (always the same) commits in my pull request.

In some cases I could at least remove some by git rebase -i but it didn't work for all and each time I create another branch from master and another pull request those unwanted commits are there again.

How to get rid of those unwanted commits completely so that my new branch starts clean? If relevant: I'm using SmartGit as git client.

Markus
  • 129
  • 1
  • 12
  • Did you try searching? There are many answers and tutorials describing how to address this common problem. – Jonathon Reinhart Sep 08 '20 at 18:31
  • The topics suggested by SO didn't look relevant. – Markus Sep 08 '20 at 19:02
  • This type of issue is typically caused by branching from a branch, and merging the original branch using squash commits and rebase. If this is what you have done, you can use git rebase --onto – Nick Sep 08 '20 at 23:08

1 Answers1

0

I'm not a SmartGit user and here is a solution in a terminal.

Firstly, check the hash of the last commit you don't want to reset with git log.
1
In this example the hash is a867b4af366350be2e7c21b8de9cc6504678a61b.

Then, type git reset --hard <commit-hash> and here you go!

maciejwww
  • 1,067
  • 1
  • 13
  • 26
  • I tried your answer but it didn't really help. I tried to apply it to the branch which already has a pull request. Maybe I need to apply this to the master branch so I can create new branches from that one which aren't polluted by these unwanted commits? – Markus Sep 13 '20 at 09:48
  • Ok, tried this on master branch, created new branch and reapplied my changes. Commited and pushed and when trying to create a pull request for this I see it has again all those other unwanted commits which are from before the commit I hard resetted to. How can I declare those old commits as "finished" "taken care of" "no longer relevant"? – Markus Sep 13 '20 at 09:55
  • After resetting, maybe try `git push -f origin master` on the branch without the newest commits (it'll force pushing your local reset branch). – maciejwww Sep 13 '20 at 12:31