How to "git reset" to an old commit and add changes WITHOUT deleting the old commits in my GitHub pull request

Issue

I want to use an older commit and add different changes (but I do not want to delete my commit history). Currently, something like this will delete the last 3 commits in my GitHub pull request history and show a new commit with my new changes:

git reset HEAD~3
git add .
git commit -m "New changes"
git push --force

Is there a way to keep my last 3 commits and then have a 4th commit with "New changes"?

What I Tried:

git reset HEAD~3
git add .
git commit -m "New changes"
git push --force

What I Want to Happen:
Add a new commit WITHOUT removing the last three commits in history

What Actually Resulted:
A new commit, in place of the last three commits.

Solution

This is done these days like this:

git restore --staged --worktree --source=HEAD~3 -- .
git commit "reverting to blahblah"

Answered By – eftshift0

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published