user1678324
user1678324

Reputation: 11

How to re-commit an existing commit after git reset

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)

Upvotes: 1

Views: 144

Answers (1)

jbialobr
jbialobr

Reputation: 1528

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.

Upvotes: 1

Related Questions