I have commits like this, 1 is the newest, and three is the oldest:
- commit 1
- commit 2
- commit 3
How to remove commit 1 and 2, but preserves the changes and commit it to the commit 3
?
I have commits like this, 1 is the newest, and three is the oldest:
How to remove commit 1 and 2, but preserves the changes and commit it to the commit 3
?
To reset last two commit you can use git reset HEAD~2
, it will remove the commit. After the commit is removed you can amend the oldest commit so it will include the changes of commit 1 and commit 2, git add --all
then git commit --amend
.
You can run git reset --soft HEAD~2
to move the HEAD branch back to an older commit (the most recent commit you want to keep).
And then simply run git commit
again with your desire changes. Before that add all the files which you want to keep your update commit.
If you want details about this please go through the bellow link. Git-Reset Demystified