Hey I am new to github so please help me out.
I have four commits.
commit4 eh87eg87
commit3 e3e983jj
commit2 de6d6e3d
commit1 du3qw6y1
I want to go back to commit2 and make changes to it and commit it (commit 5) and not lose the rest of the commits like commit4, commit3, commit2 and commit1.
You can try two things:
git rebase --interactive <ID of the commit before commit1>. Read the documentation that git prints for you. Basically, you have to useeditinstead ofpickforcommit1,amendyour commit, then continue the rebase.git reset --hard <ID of the commit before commit1>, then take each commit in order and copy them usinggit cherry-pick <ID of commit>, change the files that you want to change thengit commit --ammend, and go to the next one.