'Undo fixups on a `git rebase -i`

I've seen a few posts here on undoing a git rebase but haven't come across anything that fits my particular case.

I've run the command git rebase -i HEAD~10

After running that, I did fixup to all commits but 3

The first 2 commits is code written by someone else here but only on one file, everything else for this branch was written by me across 5 files and I am the author of the latest commit. All commits between the first 2 and the last 1, I've applied fixup.

When I look at VS Code git blame, I see all the code I wrote but it shows the other guy as the author of the code.

Is there a way for me to undo the fixup so that I can redo the fixup so that I appear as the author for the code I wrote?

An example would be:

git rebase -i HEAD~5

terminal outputs

pick 12345 Commit 1
pick 12344 Commit 2
pick 12343 Commit 3
pick 12342 Commit 4
pick 12341 Commit 5

I apply the fixup so that it now looks like

pick 12345 Commit 1
pick 12344 Commit 2
fixup 12343 Commit 3
fixup 12342 Commit 4
pick 12341 Commit 5

I've now saved these changes.

When I look at my commit history it shows

Commit 1
Commit 2
Commit 5

My goal is to revert my changes so that when I run

git rebase -i HEAD~5

It should look like this again:

pick 12345 Commit 1
pick 12344 Commit 2
pick 12343 Commit 3
pick 12342 Commit 4
pick 12341 Commit 5


Solution 1:[1]

for your case, you should follow these steps.

  1. suppose your actual working branch is Master (or dev or any other name).

  2. find your old commits which you have made a fixup by error, to do that you can run this command

    git reflog

  3. suppose now you have found your commits by SHA-1, lets say COMMIT_2, COMMIT_3 and COMMIT_4

  4. checkout the commit before the fixup commits, in your case, it is COMMIT_1

    git checkout COMMIT_1

  5. make a cheery-pick for old commits

    git cherry-pick COMMIT_2

    git cherry-pick COMMIT_3

    git cherry-pick COMMIT_4

  6. now after making cherry-pick for your COMMIT_4, you should see an other SHA-1 (commit number) for this commit, lets say COMMIT_4'

  7. go to your working branch

    git checkout Master

  8. rebase your master on the last cherry-picked commit COMMIT_4'

    git rebase COMMIT_4'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 elhadi dp ıpɐɥןǝ