0

I would like to reset a branch to a previous commit of the default branch which I have done with git checkout -b branch_name <HASH> I then pushed it to github but I don't see any changes to the default branch and hence can't open a PR. How do I PR a previous commit onto the head of the main branch ,is that even possible?

EDIT

Since you can't commit an old rev to HEAD I also tried:

git revert --no-commit 748e325fe02a668a1eed5d153666dfc927fc23a2..HEAD

but got

error: commit fdbd158a5e8dc76b323057e59344ce3392f9a049 is a merge but no -m option was given.
stdcerr
  • 13,725
  • 25
  • 71
  • 128
  • Can you add some more details? What are the branches and what exact command did you use to push? But if I think I follow what you're trying to do, you probably have to do a `git revert` instead of just rolling back to a previous commit. You can't open a PR to rollback `HEAD` of a branch. – Dan Simon Jan 19 '21 at 22:57
  • @DanSimon "You can't open a PR to rollback HEAD of a branch" Darn it, that's what I wanted... won't a revert get rid of all the commits in between? – stdcerr Jan 19 '21 at 23:08
  • If what you want is to undo all the last X commits from HEAD back to a particular commit, then I think [this](https://stackoverflow.com/a/21718540/319084) answer to a question on `git revert` sounds like what you want. It just creates a new commit that does the opposite of what the reverted commits did, so you can PR it. – Dan Simon Jan 19 '21 at 23:25
  • The error message makes it quite clear what the problem is. You are trying to make a revert that goes back past a merge commit. You can, but you must say `git revert -m` to do so, specifying which set of changes (i.e. the contribution of which parent) you want to reverse. – matt Jan 20 '21 at 02:55
  • Anyway, the goal "reset a branch to a previous commit of the default branch" is unclear. Could you give these branches names and say more exactly what you are hoping to accomplish? – matt Jan 20 '21 at 02:59

0 Answers0