1

I have a number of commits in Git history: A->B->C->D->E->F->G I have done a git reset to remove a number of last commits and preserve history based on this answer: Revert to a commit by a SHA hash in Git? git reset --hard C git reset --soft HEAD@{1} git commit -m "Reverting to the state of the project at f414f31" So, at this point I have a history: A->B->C->D->E->F->G->H where H commit reverses D->E->F->G

Now I would like E commit brought back. However if I create a new pull request based on E commit it tells that main branch is in sync with E commit and there is nothing to commit. I would expect, since E was one of the commits which was reset, to be able re-commit it. What would be the best way to it? (I do have more than 4 commits to revert and it would tedious to revert one by one)

  • Fire and see the changes in git status. If these are the changes you want to checkin, then next will will git commit. And then git push origin master(master is the origin branch here) If you dont find the changes in git status, do the respective changes and check git status again. – Praneet Nadkar Mar 22 '18 at 05:50
  • 1
    If you did a `git reset --hard C`, why do you still have `D->E->F->G` commits? Your final history there looks more like `git revert D..G` (if I remember correctly) – Lasse V. Karlsen Mar 22 '18 at 08:00

1 Answers1

1

You can try to cherry pick the E commit. See https://git-scm.com/docs/git-cherry-pick

Another option is to create a branch based on C, then cherry pick E and create a PR.

jbialobr
  • 1,382
  • 1
  • 13
  • 14