I have 3 commits (I am currently only using GIT on my local machine).
If I delete commit 2, will it affect any of the changes in commit 3 as commit 3 was followed on from commit 2?
I was planning on using:
git reset --hard <commit 2 id here>
The command
git reset --hard <commit 2 id here>
doesn't delete commit 2. This will just put your current branch on the commit 2. If no other branches point to the commit 3 you may loose it during garbage collection.
What you need is interactive rebase:
git rebase -i HEAD~2
Then you will get editor started with commit 2 and commit 3 listed. Just remove the line with the commit 2, save and exit the editor. This will remove commit 2 leaving commit 3 in tact. The parent of the commit 3 will be commit 1. All changes introduced with commit 2 will done.
I came here by the title is saying delete. So, just would like to mention if you DON'T want to keep the commits, and want to just delete them and overlap, it's also possible. If you know exactly what you're doing and would like to just purge the commit, you can overlap it by forcing the HEAD on top of the commit e.g:
git reset --hard HEAD~2
to move the HEAD by two commits behind, then push the HEAD with:
git push origin HEAD --force
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With