Search code examples
gitcommitreset

Git reset to specific comment and jump back to current commit


According to the agreement of the project I need to generate a zip file, after the completion of every phase, and send it to client. However, the previous file was found corrupted upon extraction, so I need to generate the file again.

But the problem is that I have worked far ahead in the application and I am not sure how to jump back to the commit and generate the file again which excludes the current work.

I know something about git reset --hard & git reset --soft but I am not sure how they work.

Please help.


Solution

  • I'm assuming that you must want to go back to a state where your HEAD will be pointing to the 'previous commit'. You can simply create a new branch like

    git checkout <previous-commit-hash>

    and then simply generate the file which you want.

    The options that you specified above i.e git reset --hard will cause your branch to go back to the specified commit and you would lose your current work.